dolibarr 20.0.0
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 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/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 );
112 public $rowid;
113 public $fk_skill;
114 public $rankorder;
115 public $description;
116 public $fk_user_creat;
117 public $fk_user_modif;
118 // END MODULEBUILDER PROPERTIES
119
120
121 // If this object has a subtable with lines
122
123 // /**
124 // * @var string Name of subtable line
125 // */
126 // public $table_element_line = 'hrm_skilldetline';
127
128 // /**
129 // * @var string Field with ID of parent key if this object has a parent
130 // */
131 // public $fk_element = 'fk_skilldet';
132
133 // /**
134 // * @var string Name of subtable class that manage subtable lines
135 // */
136 // public $class_element_line = 'Skilldetline';
137
138 // /**
139 // * @var array List of child tables. To test if we can delete object.
140 // */
141 // protected $childtables = array();
142
143 // /**
144 // * @var array List of child tables. To know object to delete on cascade.
145 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
146 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
147 // */
148 // protected $childtablesoncascade = array('hrm_skilldetdet');
149
150 // /**
151 // * @var SkilldetLine[] Array of subtable lines
152 // */
153 // public $lines = array();
154
155
156
162 public function __construct(DoliDB $db)
163 {
164 global $conf, $langs;
165
166 $this->db = $db;
167
168 $this->ismultientitymanaged = 0;
169 $this->isextrafieldmanaged = 1;
170
171 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
172 $this->fields['rowid']['visible'] = 0;
173 }
174 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
175 $this->fields['entity']['enabled'] = 0;
176 }
177
178 // Example to show how to set values of fields definition dynamically
179 /*if ($user->rights->hrm->skilldet->read) {
180 $this->fields['myfield']['visible'] = 1;
181 $this->fields['myfield']['noteditable'] = 0;
182 }*/
183
184 // Unset fields that are disabled
185 foreach ($this->fields as $key => $val) {
186 if (isset($val['enabled']) && empty($val['enabled'])) {
187 unset($this->fields[$key]);
188 }
189 }
190
191 // Translate some data of arrayofkeyval
192 if (is_object($langs)) {
193 foreach ($this->fields as $key => $val) {
194 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
195 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
196 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
197 }
198 }
199 }
200 }
201 }
202
210 public function create(User $user, $notrigger = 0)
211 {
212 $resultcreate = $this->createCommon($user, $notrigger);
213
214 //$resultvalidate = $this->validate($user, $notrigger);
215
216 return $resultcreate;
217 }
218
226 public function createFromClone(User $user, $fromid)
227 {
228 global $langs, $extrafields;
229 $error = 0;
230
231 dol_syslog(__METHOD__, LOG_DEBUG);
232
233 $object = new self($this->db);
234
235 $this->db->begin();
236
237 // Load source object
238 $result = $object->fetchCommon($fromid);
239 if ($result > 0 && !empty($object->table_element_line)) {
240 $object->fetchLines();
241 }
242
243 // get lines so they will be clone
244 //foreach($this->lines as $line)
245 // $line->fetch_optionals();
246
247 // Reset some properties
248 unset($object->id);
249 unset($object->fk_user_creat);
250 unset($object->import_key);
251
252 // Clear fields
253 if (property_exists($object, 'ref')) {
254 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
255 }
256 if (property_exists($object, 'label')) {
257 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
258 }
259 if (property_exists($object, 'status')) {
260 $object->status = self::STATUS_DRAFT;
261 }
262 if (property_exists($object, 'date_creation')) {
263 $object->date_creation = dol_now();
264 }
265 if (property_exists($object, 'date_modification')) {
266 $object->date_modification = null;
267 }
268 // ...
269 // Clear extrafields that are unique
270 if (is_array($object->array_options) && count($object->array_options) > 0) {
271 $extrafields->fetch_name_optionals_label($this->table_element);
272 foreach ($object->array_options as $key => $option) {
273 $shortkey = preg_replace('/options_/', '', $key);
274 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
275 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
276 unset($object->array_options[$key]);
277 }
278 }
279 }
280
281 // Create clone
282 $object->context['createfromclone'] = 'createfromclone';
283 $result = $object->createCommon($user);
284 if ($result < 0) {
285 $error++;
287 }
288
289 if (!$error) {
290 // copy internal contacts
291 if ($this->copy_linked_contact($object, 'internal') < 0) {
292 $error++;
293 }
294 }
295
296 if (!$error) {
297 // copy external contacts if same company
298 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
299 if ($this->copy_linked_contact($object, 'external') < 0) {
300 $error++;
301 }
302 }
303 }
304
305 unset($object->context['createfromclone']);
306
307 // End
308 if (!$error) {
309 $this->db->commit();
310 return $object;
311 } else {
312 $this->db->rollback();
313 return -1;
314 }
315 }
316
324 public function fetch($id, $ref = null)
325 {
326 $result = $this->fetchCommon($id, $ref);
327 if ($result > 0 && !empty($this->table_element_line)) {
328 $this->fetchLines();
329 }
330 return $result;
331 }
332
338 public function fetchLines()
339 {
340 $this->lines = array();
341
342 $result = $this->fetchLinesCommon();
343 return $result;
344 }
345
346
359 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
360 {
361 dol_syslog(__METHOD__, LOG_DEBUG);
362
363 $records = array();
364
365 $sql = 'SELECT ';
366 $sql .= $this->getFieldList('t');
367 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
368 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
369 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
370 } else {
371 $sql .= ' WHERE 1 = 1';
372 }
373
374 // Manage filter
375 $errormessage = '';
376 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
377 if ($errormessage) {
378 $this->errors[] = $errormessage;
379 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
380 return -1;
381 }
382
383 if (!empty($sortfield)) {
384 $sql .= $this->db->order($sortfield, $sortorder);
385 }
386 if (!empty($limit)) {
387 $sql .= " ".$this->db->plimit($limit, $offset);
388 }
389
390 $resql = $this->db->query($sql);
391 if ($resql) {
392 $num = $this->db->num_rows($resql);
393 $i = 0;
394 while ($i < ($limit ? min($limit, $num) : $num)) {
395 $obj = $this->db->fetch_object($resql);
396
397 $record = new self($this->db);
398 $record->setVarsFromFetchObj($obj);
399
400 $records[$record->id] = $record;
401
402 $i++;
403 }
404 $this->db->free($resql);
405
406 return $records;
407 } else {
408 $this->errors[] = 'Error '.$this->db->lasterror();
409 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
410
411 return -1;
412 }
413 }
414
422 public function update(User $user, $notrigger = 0)
423 {
424 return $this->updateCommon($user, $notrigger);
425 }
426
434 public function delete(User $user, $notrigger = 0)
435 {
436 return $this->deleteCommon($user, $notrigger);
437 //return $this->deleteCommon($user, $notrigger, 1);
438 }
439
448 public function deleteLine(User $user, $idline, $notrigger = 0)
449 {
450 if ($this->status < 0) {
451 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
452 return -2;
453 }
454
455 return $this->deleteLineCommon($user, $idline, $notrigger);
456 }
457
458
466 public function validate($user, $notrigger = 0)
467 {
468 global $conf, $langs;
469
470 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
471
472 $error = 0;
473
474 // Protection
475 if ($this->status == self::STATUS_VALIDATED) {
476 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
477 return 0;
478 }
479
480 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->write))
481 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->skilldet_advance->validate))))
482 {
483 $this->error='NotEnoughPermissions';
484 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
485 return -1;
486 }*/
487
488 $now = dol_now();
489
490 $this->db->begin();
491
492 // Define new ref
493 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
494 $num = $this->getNextNumRef();
495 } else {
496 $num = $this->ref;
497 }
498 $this->newref = $num;
499
500 if (!empty($num)) {
501 // Validate
502 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
503 $sql .= " SET ref = '".$this->db->escape($num)."',";
504 $sql .= " status = ".self::STATUS_VALIDATED;
505 if (!empty($this->fields['date_validation'])) {
506 $sql .= ", date_validation = '".$this->db->idate($now)."'";
507 }
508 if (!empty($this->fields['fk_user_valid'])) {
509 $sql .= ", fk_user_valid = ".((int) $user->id);
510 }
511 $sql .= " WHERE rowid = ".((int) $this->id);
512
513 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
514 $resql = $this->db->query($sql);
515 if (!$resql) {
516 dol_print_error($this->db);
517 $this->error = $this->db->lasterror();
518 $error++;
519 }
520
521 if (!$error && !$notrigger) {
522 // Call trigger
523 $result = $this->call_trigger('HRM_SKILLDET_VALIDATE', $user);
524 if ($result < 0) {
525 $error++;
526 }
527 // End call triggers
528 }
529 }
530
531 if (!$error) {
532 $this->oldref = $this->ref;
533
534 // Rename directory if dir was a temporary ref
535 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
536 // Now we rename also files into index
537 $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)."'";
538 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
539 $resql = $this->db->query($sql);
540 if (!$resql) {
541 $error++;
542 $this->error = $this->db->lasterror();
543 }
544 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skilldet/".$this->db->escape($this->newref)."'";
545 $sql .= " WHERE filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
546 $resql = $this->db->query($sql);
547 if (!$resql) {
548 $error++;
549 $this->error = $this->db->lasterror();
550 }
551
552 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
553 $oldref = dol_sanitizeFileName($this->ref);
554 $newref = dol_sanitizeFileName($num);
555 $dirsource = $conf->hrm->dir_output.'/skilldet/'.$oldref;
556 $dirdest = $conf->hrm->dir_output.'/skilldet/'.$newref;
557 if (!$error && file_exists($dirsource)) {
558 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
559
560 if (@rename($dirsource, $dirdest)) {
561 dol_syslog("Rename ok");
562 // Rename docs starting with $oldref with $newref
563 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skilldet/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
564 foreach ($listoffiles as $fileentry) {
565 $dirsource = $fileentry['name'];
566 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
567 $dirsource = $fileentry['path'].'/'.$dirsource;
568 $dirdest = $fileentry['path'].'/'.$dirdest;
569 @rename($dirsource, $dirdest);
570 }
571 }
572 }
573 }
574 }
575
576 // Set new ref and current status
577 if (!$error) {
578 $this->ref = $num;
579 $this->status = self::STATUS_VALIDATED;
580 }
581
582 if (!$error) {
583 $this->db->commit();
584 return 1;
585 } else {
586 $this->db->rollback();
587 return -1;
588 }
589 }
590
591
599 public function setDraft($user, $notrigger = 0)
600 {
601 // Protection
602 if ($this->status <= self::STATUS_DRAFT) {
603 return 0;
604 }
605
606 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
607 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
608 {
609 $this->error='Permission denied';
610 return -1;
611 }*/
612
613 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLDET_UNVALIDATE');
614 }
615
623 public function cancel($user, $notrigger = 0)
624 {
625 // Protection
626 if ($this->status != self::STATUS_VALIDATED) {
627 return 0;
628 }
629
630 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
631 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
632 {
633 $this->error='Permission denied';
634 return -1;
635 }*/
636
637 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLDET_CANCEL');
638 }
639
647 public function reopen($user, $notrigger = 0)
648 {
649 // Protection
650 if ($this->status != self::STATUS_CANCELED) {
651 return 0;
652 }
653
654 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
655 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
656 {
657 $this->error='Permission denied';
658 return -1;
659 }*/
660
661 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLDET_REOPEN');
662 }
663
674 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
675 {
676 global $conf, $langs, $hookmanager;
677
678 if (!empty($conf->dol_no_mouse_hover)) {
679 $notooltip = 1; // Force disable tooltips
680 }
681
682 $result = '';
683
684 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skilldet").'</u>';
685 if (isset($this->status)) {
686 $label .= ' '.$this->getLibStatut(5);
687 }
688 $label .= '<br>';
689 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
690
691 $url = dol_buildpath('/hrm/skilldet_card.php', 1).'?id='.$this->id;
692
693 if ($option != 'nolink') {
694 // Add param to save lastsearch_values or not
695 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
696 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
697 $add_save_lastsearch_values = 1;
698 }
699 if ($add_save_lastsearch_values) {
700 $url .= '&save_lastsearch_values=1';
701 }
702 }
703
704 $linkclose = '';
705 if (empty($notooltip)) {
706 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
707 $label = $langs->trans("ShowSkilldet");
708 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
709 }
710 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
711 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
712 } else {
713 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
714 }
715
716 if ($option == 'nolink') {
717 $linkstart = '<span';
718 } else {
719 $linkstart = '<a href="'.$url.'"';
720 }
721 $linkstart .= $linkclose.'>';
722 if ($option == 'nolink') {
723 $linkend = '</span>';
724 } else {
725 $linkend = '</a>';
726 }
727
728 $result .= $linkstart;
729
730 if (empty($this->showphoto_on_popup)) {
731 if ($withpicto) {
732 $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);
733 }
734 } else {
735 if ($withpicto) {
736 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
737
738 list($class, $module) = explode('@', $this->picto);
739 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
740 $filearray = dol_dir_list($upload_dir, "files");
741 $filename = $filearray[0]['name'];
742 if (!empty($filename)) {
743 $pospoint = strpos($filearray[0]['name'], '.');
744
745 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
746 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
747 $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>';
748 } else {
749 $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>';
750 }
751
752 $result .= '</div>';
753 } else {
754 $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);
755 }
756 }
757 }
758
759 if ($withpicto != 2) {
760 $result .= $this->ref;
761 }
762
763 $result .= $linkend;
764 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
765
766 global $action, $hookmanager;
767 $hookmanager->initHooks(array('skilldetdao'));
768 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
769 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
770 if ($reshook > 0) {
771 $result = $hookmanager->resPrint;
772 } else {
773 $result .= $hookmanager->resPrint;
774 }
775
776 return $result;
777 }
778
785 public function getLibStatut($mode = 0)
786 {
787 return $this->LibStatut($this->status, $mode);
788 }
789
790 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
798 public function LibStatut($status, $mode = 0)
799 {
800 // phpcs:enable
801 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
802 global $langs;
803 //$langs->load("hrm");
804 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
805 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
806 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
807 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
808 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
809 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
810 }
811
812 $statusType = 'status'.$status;
813 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
814 if ($status == self::STATUS_CANCELED) {
815 $statusType = 'status6';
816 }
817
818 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
819 }
820
827 public function info($id)
828 {
829 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
830 $sql .= ' fk_user_creat, fk_user_modif';
831 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
832 $sql .= ' WHERE t.rowid = '.((int) $id);
833 $result = $this->db->query($sql);
834 if ($result) {
835 if ($this->db->num_rows($result)) {
836 $obj = $this->db->fetch_object($result);
837
838 $this->id = $obj->rowid;
839
840 $this->user_creation_id = $obj->fk_user_creat;
841 $this->user_modification_id = $obj->fk_user_modif;
842 $this->date_creation = $this->db->jdate($obj->datec);
843 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
844 }
845
846 $this->db->free($result);
847 } else {
848 dol_print_error($this->db);
849 }
850 }
851
858 public function initAsSpecimen()
859 {
860 // Set here init that are not commonf fields
861 // $this->property1 = ...
862 // $this->property2 = ...
863
864 return $this->initAsSpecimenCommon();
865 }
866
867
873 public function getNextNumRef()
874 {
875 global $langs, $conf;
876 $langs->load("hrm");
877
878 if (!getDolGlobalString('hrm_SKILLDET_ADDON')) {
879 $conf->global->hrm_SKILLDET_ADDON = 'mod_skilldet_standard';
880 }
881
882 if (getDolGlobalString('hrm_SKILLDET_ADDON')) {
883 $mybool = false;
884
885 $file = getDolGlobalString('hrm_SKILLDET_ADDON') . ".php";
886 $classname = getDolGlobalString('hrm_SKILLDET_ADDON');
887
888 // Include file with class
889 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
890 foreach ($dirmodels as $reldir) {
891 $dir = dol_buildpath($reldir."core/modules/hrm/");
892
893 // Load file with numbering class (if found)
894 $mybool = ((bool) @include_once $dir.$file) || $mybool;
895 }
896
897 if ($mybool === false) {
898 dol_print_error(null, "Failed to include file ".$file);
899 return '';
900 }
901
902 if (class_exists($classname)) {
903 $obj = new $classname();
904 $numref = $obj->getNextValue($this);
905
906 if ($numref != '' && $numref != '-1') {
907 return $numref;
908 } else {
909 $this->error = $obj->error;
910 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
911 return "";
912 }
913 } else {
914 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
915 return "";
916 }
917 } else {
918 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
919 return "";
920 }
921 }
922
934 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
935 {
936 global $conf, $langs;
937
938 $result = 0;
939 $includedocgeneration = 0;
940
941 $langs->load("hrm");
942
943 if (!dol_strlen($modele)) {
944 $modele = 'standard_skilldet';
945
946 if (!empty($this->model_pdf)) {
947 $modele = $this->model_pdf;
948 } elseif (getDolGlobalString('SKILLDET_ADDON_PDF')) {
949 $modele = getDolGlobalString('SKILLDET_ADDON_PDF');
950 }
951 }
952
953 $modelpath = "core/modules/hrm/doc/";
954
955 if ($includedocgeneration && !empty($modele)) {
956 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
957 }
958
959 return $result;
960 }
961}
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:637
$object ref
Definition info.php:79
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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)
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.
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...
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.