dolibarr 25.0.0-alpha
skilldet.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5 * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6 * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
32
37{
41 public $module = 'hrm';
42
46 public $element = 'skilldet';
47
51 public $table_element = 'hrm_skilldet';
52
56 public $parent_element = 'skill';
57
61 public $fk_parent_attribute = 'fk_skill';
62
66 public $picto = 'skilldet@hrm';
67
68
69 const STATUS_DRAFT = 0;
70 const STATUS_VALIDATED = 1;
71 const STATUS_CANCELED = 9;
72
73
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields = array(
105 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
106 'fk_skill' => array('type' => 'integer:Skill:/hrm/class/skill.class.php', 'label' => 'fk_skill', 'enabled' => 1, 'position' => 5, 'notnull' => 1, 'visible' => 0,),
107 'rankorder' => array('type' => 'integer', 'label' => 'rank', 'enabled' => 1, 'position' => 10, 'notnull' => 0, 'visible' => 2,),
108 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 1,),
109 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
110 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => 0,),
111 );
115 public $rowid;
119 public $fk_skill;
123 public $rankorder;
127 public $description;
131 public $fk_user_creat;
135 public $fk_user_modif;
136 // END MODULEBUILDER PROPERTIES
137
138
139 // If this object has a subtable with lines
140
141 // /**
142 // * @var string Name of subtable line
143 // */
144 // public $table_element_line = 'hrm_skilldetline';
145
146 // /**
147 // * @var string Field with ID of parent key if this object has a parent
148 // */
149 // public $fk_element = 'fk_skilldet';
150
151 // /**
152 // * @var string Name of subtable class that manage subtable lines
153 // */
154 // public $class_element_line = 'Skilldetline';
155
156 // /**
157 // * @var array List of child tables. To test if we can delete object.
158 // */
159 // protected $childtables = array();
160
161 // /**
162 // * @var array List of child tables. To know object to delete on cascade.
163 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
164 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
165 // */
166 // protected $childtablesoncascade = array('hrm_skilldetdet');
167
168 // /**
169 // * @var SkilldetLine[] Array of subtable lines
170 // */
171 // public $lines = array();
172
173
174
180 public function __construct(DoliDB $db)
181 {
182 global $langs;
183
184 $this->db = $db;
185
186 $this->ismultientitymanaged = 0;
187 $this->isextrafieldmanaged = 1;
188
189 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
190 $this->fields['rowid']['visible'] = 0;
191 }
192 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
193 $this->fields['entity']['enabled'] = 0;
194 }
195
196 // Unset fields that are disabled
197 foreach ($this->fields as $key => $val) {
198 if (isset($val['enabled']) && empty($val['enabled'])) {
199 unset($this->fields[$key]);
200 }
201 }
202
203 // Translate some data of arrayofkeyval
204 if (is_object($langs)) {
205 foreach ($this->fields as $key => $val) {
206 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
207 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
208 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
209 }
210 }
211 }
212 }
213 }
214
222 public function create(User $user, $notrigger = 0)
223 {
224 $resultcreate = $this->createCommon($user, $notrigger);
225
226 //$resultvalidate = $this->validate($user, $notrigger);
227
228 return $resultcreate;
229 }
230
238 public function createFromClone(User $user, $fromid)
239 {
240 global $extrafields;
241
242 $error = 0;
243
244 dol_syslog(__METHOD__, LOG_DEBUG);
245
246 $object = new self($this->db);
247
248 $this->db->begin();
249
250 // Load source object
251 $result = $object->fetchCommon($fromid);
252 if ($result > 0 && !empty($object->table_element_line)) {
253 $object->fetchLines();
254 }
255
256 // get lines so they will be clone
257 //foreach($this->lines as $line)
258 // $line->fetch_optionals();
259
260 // Reset some properties
261 unset($object->id);
262 unset($object->fk_user_creat);
263 unset($object->user_creation_id);
264 unset($object->import_key);
265
266 // Clear fields
267 if (property_exists($object, 'ref')) {
268 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
269 }
270 if (property_exists($object, 'status')) {
271 $object->status = self::STATUS_DRAFT;
272 }
273 if (property_exists($object, 'date_creation')) {
274 $object->date_creation = dol_now();
275 }
276 if (property_exists($object, 'date_modification')) {
277 $object->date_modification = null;
278 }
279 // ...
280 // Clear extrafields that are unique
281 if (is_array($object->array_options) && count($object->array_options) > 0) {
282 $extrafields->fetch_name_optionals_label($this->table_element);
283 foreach ($object->array_options as $key => $option) {
284 $shortkey = preg_replace('/options_/', '', $key);
285 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
286 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
287 unset($object->array_options[$key]);
288 }
289 }
290 }
291
292 // Create clone
293 $object->context['createfromclone'] = 'createfromclone';
294 $result = $object->createCommon($user);
295 if ($result < 0) {
296 $error++;
298 }
299
300 if (!$error) {
301 // copy internal contacts
302 if ($this->copy_linked_contact($object, 'internal') < 0) {
303 $error++;
304 }
305 }
306
307 unset($object->context['createfromclone']);
308
309 // End
310 if (!$error) {
311 $this->db->commit();
312 return $object;
313 } else {
314 $this->db->rollback();
315 return -1;
316 }
317 }
318
326 public function fetch($id, $ref = null)
327 {
328 $result = $this->fetchCommon($id, $ref);
329 if ($result > 0 && !empty($this->table_element_line)) {
330 $this->fetchLines();
331 }
332 return $result;
333 }
334
340 public function fetchLines()
341 {
342 $this->lines = array();
343
344 $result = $this->fetchLinesCommon();
345 return $result;
346 }
347
348
361 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
362 {
363 dol_syslog(__METHOD__, LOG_DEBUG);
364
365 $records = array();
366
367 $sql = 'SELECT ';
368 $sql .= $this->getFieldList('t');
369 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
370 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
371 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
372 } else {
373 $sql .= ' WHERE 1 = 1';
374 }
375
376 // Manage filter
377 $errormessage = '';
378 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
379 if ($errormessage) {
380 $this->errors[] = $errormessage;
381 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
382 return -1;
383 }
384
385 if (!empty($sortfield)) {
386 $sql .= $this->db->order($sortfield, $sortorder);
387 }
388 if (!empty($limit)) {
389 $sql .= " ".$this->db->plimit($limit, $offset);
390 }
391
392 $resql = $this->db->query($sql);
393 if ($resql) {
394 $num = $this->db->num_rows($resql);
395 $i = 0;
396 while ($i < ($limit ? min($limit, $num) : $num)) {
397 $obj = $this->db->fetch_object($resql);
398
399 $record = new self($this->db);
400 $record->setVarsFromFetchObj($obj);
401
402 $records[$record->id] = $record;
403
404 $i++;
405 }
406 $this->db->free($resql);
407
408 return $records;
409 } else {
410 $this->errors[] = 'Error '.$this->db->lasterror();
411 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
412
413 return -1;
414 }
415 }
416
424 public function update(User $user, $notrigger = 0)
425 {
426 return $this->updateCommon($user, $notrigger);
427 }
428
436 public function delete(User $user, $notrigger = 0)
437 {
438 return $this->deleteCommon($user, $notrigger);
439 //return $this->deleteCommon($user, $notrigger, 1);
440 }
441
450 public function deleteLine(User $user, $idline, $notrigger = 0)
451 {
452 if ($this->status < 0) {
453 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
454 return -2;
455 }
456
457 return $this->deleteLineCommon($user, $idline, $notrigger);
458 }
459
460
468 public function validate($user, $notrigger = 0)
469 {
470 global $conf;
471
472 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
473
474 $error = 0;
475
476 // Protection
477 if ($this->status == self::STATUS_VALIDATED) {
478 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
479 return 0;
480 }
481
482 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->write))
483 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->skilldet_advance->validate))))
484 {
485 $this->error='NotEnoughPermissions';
486 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
487 return -1;
488 }*/
489
490 $now = dol_now();
491
492 $this->db->begin();
493
494 // Define new ref
495 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
496 $num = $this->getNextNumRef();
497 } else {
498 $num = (string) $this->ref;
499 }
500 $this->newref = $num;
501
502 if (!empty($num)) {
503 // Validate
504 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
505 $sql .= " SET ref = '".$this->db->escape($num)."',";
506 $sql .= " status = ".self::STATUS_VALIDATED;
507 if (!empty($this->fields['date_validation'])) {
508 $sql .= ", date_validation = '".$this->db->idate($now)."'";
509 }
510 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
511 $sql .= ", fk_user_valid = ".((int) $user->id);
512 }
513 $sql .= " WHERE rowid = ".((int) $this->id);
514
515 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
516 $resql = $this->db->query($sql);
517 if (!$resql) {
518 dol_print_error($this->db);
519 $this->error = $this->db->lasterror();
520 $error++;
521 }
522
523 if (!$error && !$notrigger) {
524 // Call trigger
525 $result = $this->call_trigger('HRM_SKILLDET_VALIDATE', $user);
526 if ($result < 0) {
527 $error++;
528 }
529 // End call triggers
530 }
531 }
532
533 if (!$error) {
534 $this->oldref = $this->ref;
535
536 // Rename directory if dir was a temporary ref
537 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
538 // Now we rename also files into index
539 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skilldet/".$this->db->escape($this->newref)."'";
540 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
541 $resql = $this->db->query($sql);
542 if (!$resql) {
543 $error++;
544 $this->error = $this->db->lasterror();
545 }
546 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skilldet/".$this->db->escape($this->newref)."'";
547 $sql .= " WHERE filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
548 $resql = $this->db->query($sql);
549 if (!$resql) {
550 $error++;
551 $this->error = $this->db->lasterror();
552 }
553
554 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
555 $oldref = dol_sanitizeFileName($this->ref);
556 $newref = dol_sanitizeFileName($num);
557 $dirsource = $conf->hrm->dir_output.'/skilldet/'.$oldref;
558 $dirdest = $conf->hrm->dir_output.'/skilldet/'.$newref;
559 if (!$error && file_exists($dirsource)) {
560 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
561
562 if (@rename($dirsource, $dirdest)) {
563 dol_syslog("Rename ok");
564 // Rename docs starting with $oldref with $newref
565 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skilldet/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
566 foreach ($listoffiles as $fileentry) {
567 $dirsource = $fileentry['name'];
568 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
569 $dirsource = $fileentry['path'].'/'.$dirsource;
570 $dirdest = $fileentry['path'].'/'.$dirdest;
571 @rename($dirsource, $dirdest);
572 }
573 }
574 }
575 }
576 }
577
578 // Set new ref and current status
579 if (!$error) {
580 $this->ref = $num;
581 $this->status = self::STATUS_VALIDATED;
582 }
583
584 if (!$error) {
585 $this->db->commit();
586 return 1;
587 } else {
588 $this->db->rollback();
589 return -1;
590 }
591 }
592
593
601 public function setDraft($user, $notrigger = 0)
602 {
603 // Protection
604 if ($this->status <= self::STATUS_DRAFT) {
605 return 0;
606 }
607
608 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
609 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
610 {
611 $this->error='Permission denied';
612 return -1;
613 }*/
614
615 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLDET_UNVALIDATE');
616 }
617
625 public function cancel($user, $notrigger = 0)
626 {
627 // Protection
628 if ($this->status != self::STATUS_VALIDATED) {
629 return 0;
630 }
631
632 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
633 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
634 {
635 $this->error='Permission denied';
636 return -1;
637 }*/
638
639 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLDET_CANCEL');
640 }
641
649 public function reopen($user, $notrigger = 0)
650 {
651 // Protection
652 if ($this->status != self::STATUS_CANCELED) {
653 return 0;
654 }
655
656 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
657 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
658 {
659 $this->error='Permission denied';
660 return -1;
661 }*/
662
663 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLDET_REOPEN');
664 }
665
676 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
677 {
678 global $conf, $langs, $hookmanager;
679
680 if (!empty($conf->dol_no_mouse_hover)) {
681 $notooltip = 1; // Force disable tooltips
682 }
683
684 $result = '';
685
686 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skilldet").'</u>';
687 if (isset($this->status)) {
688 $label .= ' '.$this->getLibStatut(5);
689 }
690 $label .= '<br>';
691 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
692
693 $url = dol_buildpath('/hrm/skilldet_card.php', 1).'?id='.$this->id;
694
695 if ($option != 'nolink') {
696 // Add param to save lastsearch_values or not
697 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
698 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
699 $add_save_lastsearch_values = 1;
700 }
701 if ($add_save_lastsearch_values) {
702 $url .= '&save_lastsearch_values=1';
703 }
704 }
705
706 $linkclose = '';
707 if (empty($notooltip)) {
708 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
709 $label = $langs->trans("ShowSkilldet");
710 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
711 }
712 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
713 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
714 } else {
715 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
716 }
717
718 if ($option == 'nolink') {
719 $linkstart = '<span';
720 } else {
721 $linkstart = '<a href="'.$url.'"';
722 }
723 $linkstart .= $linkclose.'>';
724 if ($option == 'nolink') {
725 $linkend = '</span>';
726 } else {
727 $linkend = '</a>';
728 }
729
730 $result .= $linkstart;
731
732 if (empty($this->showphoto_on_popup)) {
733 if ($withpicto) {
734 $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);
735 }
736 } else {
737 if ($withpicto) {
738 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
739
740 list($class, $module) = explode('@', $this->picto);
741 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
742 $filearray = dol_dir_list($upload_dir, "files");
743 $filename = $filearray[0]['name'];
744 if (!empty($filename)) {
745 $pospoint = strpos($filearray[0]['name'], '.');
746
747 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
748 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
749 $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>';
750 } else {
751 $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>';
752 }
753
754 $result .= '</div>';
755 } else {
756 $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);
757 }
758 }
759 }
760
761 if ($withpicto != 2) {
762 $result .= $this->ref;
763 }
764
765 $result .= $linkend;
766 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
767
768 global $action, $hookmanager;
769 $hookmanager->initHooks(array('skilldetdao'));
770 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
771 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
772 if ($reshook > 0) {
773 $result = $hookmanager->resPrint;
774 } else {
775 $result .= $hookmanager->resPrint;
776 }
777
778 return $result;
779 }
780
787 public function getLibStatut($mode = 0)
788 {
789 return $this->LibStatut($this->status, $mode);
790 }
791
792 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
800 public function LibStatut($status, $mode = 0)
801 {
802 // phpcs:enable
803 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
804 global $langs;
805 //$langs->load("hrm");
806 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
807 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
808 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
809 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
810 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
811 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
812 }
813
814 $statusType = 'status'.$status;
815 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
816 if ($status == self::STATUS_CANCELED) {
817 $statusType = 'status6';
818 }
819
820 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
821 }
822
829 public function info($id)
830 {
831 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
832 $sql .= ' fk_user_creat, fk_user_modif';
833 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
834 $sql .= ' WHERE t.rowid = '.((int) $id);
835 $result = $this->db->query($sql);
836 if ($result) {
837 if ($this->db->num_rows($result)) {
838 $obj = $this->db->fetch_object($result);
839
840 $this->id = $obj->rowid;
841
842 $this->user_creation_id = $obj->fk_user_creat;
843 $this->user_modification_id = $obj->fk_user_modif;
844 $this->date_creation = $this->db->jdate($obj->datec);
845 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
846 }
847
848 $this->db->free($result);
849 } else {
850 dol_print_error($this->db);
851 }
852 }
853
860 public function initAsSpecimen()
861 {
862 // Set here init that are not commonf fields
863 // $this->property1 = ...
864 // $this->property2 = ...
865
866 return $this->initAsSpecimenCommon();
867 }
868
869
875 public function getNextNumRef()
876 {
877 global $langs, $conf;
878 $langs->load("hrm");
879
880 if (!getDolGlobalString('hrm_SKILLDET_ADDON')) {
881 $conf->global->hrm_SKILLDET_ADDON = 'mod_skilldet_standard';
882 }
883
884 if (getDolGlobalString('hrm_SKILLDET_ADDON')) {
885 $mybool = false;
886
887 $file = getDolGlobalString('hrm_SKILLDET_ADDON') . ".php";
888 $classname = getDolGlobalString('hrm_SKILLDET_ADDON');
889
890 // Include file with class
891 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
892 foreach ($dirmodels as $reldir) {
893 $dir = dol_buildpath($reldir."core/modules/hrm/");
894
895 // Load file with numbering class (if found)
896 $mybool = ((bool) @include_once $dir.$file) || $mybool;
897 }
898
899 if (!$mybool) {
900 dol_print_error(null, "Failed to include file ".$file);
901 return '';
902 }
903
904 if (class_exists($classname)) {
905 $obj = new $classname();
906 '@phan-var-force ModeleNumRefEvaluation $obj';
907 $numref = $obj->getNextValue($this);
908
909 if ($numref != '' && $numref != '-1') {
910 return $numref;
911 } else {
912 $this->error = $obj->error;
913 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
914 return "";
915 }
916 } else {
917 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
918 return "";
919 }
920 } else {
921 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
922 return "";
923 }
924 }
925
937 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
938 {
939 global $langs;
940
941 $result = 0;
942 $includedocgeneration = 0;
943
944 $langs->load("hrm");
945
946 if (!dol_strlen($modele)) {
947 $modele = 'standard_skilldet';
948
949 if (!empty($this->model_pdf)) {
950 $modele = $this->model_pdf;
951 } elseif (getDolGlobalString('SKILLDET_ADDON_PDF')) {
952 $modele = getDolGlobalString('SKILLDET_ADDON_PDF');
953 }
954 }
955
956 $modelpath = "core/modules/hrm/doc/";
957
958 if ($includedocgeneration && !empty($modele)) {
959 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
960 }
961
962 return $result;
963 }
964}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
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.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Skilldet.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
update(User $user, $notrigger=0)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
cancel($user, $notrigger=0)
Set cancel status.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
create(User $user, $notrigger=0)
Create object into database.
LibStatut($status, $mode=0)
Return the status.
fetchLines()
Load object lines in memory from the database.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
createFromClone(User $user, $fromid)
Clone an object into another one.
validate($user, $notrigger=0)
Validate object.
info($id)
Load the info information in the object.
reopen($user, $notrigger=0)
Set back to validated status.
setDraft($user, $notrigger=0)
Set draft status.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.