dolibarr 19.0.3
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32
37{
41 public $module = 'hrm';
42
46 public $element = 'skilldet';
47
51 public $table_element = 'hrm_skilldet';
52
57 public $ismultientitymanaged = 0;
58
62 public $isextrafieldmanaged = 1;
63
67 public $picto = 'skilldet@hrm';
68
69
70 const STATUS_DRAFT = 0;
71 const STATUS_VALIDATED = 1;
72 const STATUS_CANCELED = 9;
73
74
101 // BEGIN MODULEBUILDER PROPERTIES
105 public $fields=array(
106 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
107 'fk_skill' => array('type'=>'integer:Skill:/hrm/class/skill.class.php', 'label'=>'fk_skill', 'enabled'=>'1', 'position'=>5, 'notnull'=>1, 'visible'=>0,),
108 'rankorder' => array('type'=>'integer', 'label'=>'rank', 'enabled'=>'1', 'position'=>10, 'notnull'=>0, 'visible'=>2,),
109 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>60, 'notnull'=>0, 'visible'=>1,),
110 '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',),
111 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>0,),
112 );
113 public $rowid;
114 public $fk_skill;
115 public $rankorder;
116 public $description;
117 public $fk_user_creat;
118 public $fk_user_modif;
119 // END MODULEBUILDER PROPERTIES
120
121
122 // If this object has a subtable with lines
123
124 // /**
125 // * @var string Name of subtable line
126 // */
127 // public $table_element_line = 'hrm_skilldetline';
128
129 // /**
130 // * @var string Field with ID of parent key if this object has a parent
131 // */
132 // public $fk_element = 'fk_skilldet';
133
134 // /**
135 // * @var string Name of subtable class that manage subtable lines
136 // */
137 // public $class_element_line = 'Skilldetline';
138
139 // /**
140 // * @var array List of child tables. To test if we can delete object.
141 // */
142 // protected $childtables = array();
143
144 // /**
145 // * @var array List of child tables. To know object to delete on cascade.
146 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
147 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
148 // */
149 // protected $childtablesoncascade = array('hrm_skilldetdet');
150
151 // /**
152 // * @var SkilldetLine[] Array of subtable lines
153 // */
154 // public $lines = array();
155
156
157
163 public function __construct(DoliDB $db)
164 {
165 global $conf, $langs;
166
167 $this->db = $db;
168
169 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
170 $this->fields['rowid']['visible'] = 0;
171 }
172 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
173 $this->fields['entity']['enabled'] = 0;
174 }
175
176 // Example to show how to set values of fields definition dynamically
177 /*if ($user->rights->hrm->skilldet->read) {
178 $this->fields['myfield']['visible'] = 1;
179 $this->fields['myfield']['noteditable'] = 0;
180 }*/
181
182 // Unset fields that are disabled
183 foreach ($this->fields as $key => $val) {
184 if (isset($val['enabled']) && empty($val['enabled'])) {
185 unset($this->fields[$key]);
186 }
187 }
188
189 // Translate some data of arrayofkeyval
190 if (is_object($langs)) {
191 foreach ($this->fields as $key => $val) {
192 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
193 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
194 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
195 }
196 }
197 }
198 }
199 }
200
208 public function create(User $user, $notrigger = false)
209 {
210 $resultcreate = $this->createCommon($user, $notrigger);
211
212 //$resultvalidate = $this->validate($user, $notrigger);
213
214 return $resultcreate;
215 }
216
224 public function createFromClone(User $user, $fromid)
225 {
226 global $langs, $extrafields;
227 $error = 0;
228
229 dol_syslog(__METHOD__, LOG_DEBUG);
230
231 $object = new self($this->db);
232
233 $this->db->begin();
234
235 // Load source object
236 $result = $object->fetchCommon($fromid);
237 if ($result > 0 && !empty($object->table_element_line)) {
238 $object->fetchLines();
239 }
240
241 // get lines so they will be clone
242 //foreach($this->lines as $line)
243 // $line->fetch_optionals();
244
245 // Reset some properties
246 unset($object->id);
247 unset($object->fk_user_creat);
248 unset($object->import_key);
249
250 // Clear fields
251 if (property_exists($object, 'ref')) {
252 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
253 }
254 if (property_exists($object, 'label')) {
255 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
256 }
257 if (property_exists($object, 'status')) {
258 $object->status = self::STATUS_DRAFT;
259 }
260 if (property_exists($object, 'date_creation')) {
261 $object->date_creation = dol_now();
262 }
263 if (property_exists($object, 'date_modification')) {
264 $object->date_modification = null;
265 }
266 // ...
267 // Clear extrafields that are unique
268 if (is_array($object->array_options) && count($object->array_options) > 0) {
269 $extrafields->fetch_name_optionals_label($this->table_element);
270 foreach ($object->array_options as $key => $option) {
271 $shortkey = preg_replace('/options_/', '', $key);
272 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
273 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
274 unset($object->array_options[$key]);
275 }
276 }
277 }
278
279 // Create clone
280 $object->context['createfromclone'] = 'createfromclone';
281 $result = $object->createCommon($user);
282 if ($result < 0) {
283 $error++;
284 $this->error = $object->error;
285 $this->errors = $object->errors;
286 }
287
288 if (!$error) {
289 // copy internal contacts
290 if ($this->copy_linked_contact($object, 'internal') < 0) {
291 $error++;
292 }
293 }
294
295 if (!$error) {
296 // copy external contacts if same company
297 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
298 if ($this->copy_linked_contact($object, 'external') < 0) {
299 $error++;
300 }
301 }
302 }
303
304 unset($object->context['createfromclone']);
305
306 // End
307 if (!$error) {
308 $this->db->commit();
309 return $object;
310 } else {
311 $this->db->rollback();
312 return -1;
313 }
314 }
315
323 public function fetch($id, $ref = null)
324 {
325 $result = $this->fetchCommon($id, $ref);
326 if ($result > 0 && !empty($this->table_element_line)) {
327 $this->fetchLines();
328 }
329 return $result;
330 }
331
337 public function fetchLines()
338 {
339 $this->lines = array();
340
341 $result = $this->fetchLinesCommon();
342 return $result;
343 }
344
345
357 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
358 {
359 dol_syslog(__METHOD__, LOG_DEBUG);
360
361 $records = array();
362
363 $sql = 'SELECT ';
364 $sql .= $this->getFieldList('t');
365 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
366 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
367 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
368 } else {
369 $sql .= ' WHERE 1 = 1';
370 }
371 // Manage filter
372 $sqlwhere = array();
373 if (count($filter) > 0) {
374 foreach ($filter as $key => $value) {
375 if ($key == 't.rowid') {
376 $sqlwhere[] = $key.'='.$value;
377 } elseif ($key == 'customsql') {
378 $sqlwhere[] = $value;
379 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
380 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
381 } elseif (strpos($value, '%') === false) {
382 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
383 } else {
384 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
385 }
386 }
387 }
388 if (count($sqlwhere) > 0) {
389 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
390 }
391
392 if (!empty($sortfield)) {
393 $sql .= $this->db->order($sortfield, $sortorder);
394 }
395 if (!empty($limit)) {
396 $sql .= " ".$this->db->plimit($limit, $offset);
397 }
398
399 $resql = $this->db->query($sql);
400 if ($resql) {
401 $num = $this->db->num_rows($resql);
402 $i = 0;
403 while ($i < ($limit ? min($limit, $num) : $num)) {
404 $obj = $this->db->fetch_object($resql);
405
406 $record = new self($this->db);
407 $record->setVarsFromFetchObj($obj);
408
409 $records[$record->id] = $record;
410
411 $i++;
412 }
413 $this->db->free($resql);
414
415 return $records;
416 } else {
417 $this->errors[] = 'Error '.$this->db->lasterror();
418 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
419
420 return -1;
421 }
422 }
423
431 public function update(User $user, $notrigger = false)
432 {
433 return $this->updateCommon($user, $notrigger);
434 }
435
443 public function delete(User $user, $notrigger = false)
444 {
445 return $this->deleteCommon($user, $notrigger);
446 //return $this->deleteCommon($user, $notrigger, 1);
447 }
448
457 public function deleteLine(User $user, $idline, $notrigger = false)
458 {
459 if ($this->status < 0) {
460 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
461 return -2;
462 }
463
464 return $this->deleteLineCommon($user, $idline, $notrigger);
465 }
466
467
475 public function validate($user, $notrigger = 0)
476 {
477 global $conf, $langs;
478
479 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
480
481 $error = 0;
482
483 // Protection
484 if ($this->status == self::STATUS_VALIDATED) {
485 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
486 return 0;
487 }
488
489 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->write))
490 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skilldet->skilldet_advance->validate))))
491 {
492 $this->error='NotEnoughPermissions';
493 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
494 return -1;
495 }*/
496
497 $now = dol_now();
498
499 $this->db->begin();
500
501 // Define new ref
502 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
503 $num = $this->getNextNumRef();
504 } else {
505 $num = $this->ref;
506 }
507 $this->newref = $num;
508
509 if (!empty($num)) {
510 // Validate
511 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
512 $sql .= " SET ref = '".$this->db->escape($num)."',";
513 $sql .= " status = ".self::STATUS_VALIDATED;
514 if (!empty($this->fields['date_validation'])) {
515 $sql .= ", date_validation = '".$this->db->idate($now)."'";
516 }
517 if (!empty($this->fields['fk_user_valid'])) {
518 $sql .= ", fk_user_valid = ".((int) $user->id);
519 }
520 $sql .= " WHERE rowid = ".((int) $this->id);
521
522 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
523 $resql = $this->db->query($sql);
524 if (!$resql) {
525 dol_print_error($this->db);
526 $this->error = $this->db->lasterror();
527 $error++;
528 }
529
530 if (!$error && !$notrigger) {
531 // Call trigger
532 $result = $this->call_trigger('HRM_SKILLDET_VALIDATE', $user);
533 if ($result < 0) {
534 $error++;
535 }
536 // End call triggers
537 }
538 }
539
540 if (!$error) {
541 $this->oldref = $this->ref;
542
543 // Rename directory if dir was a temporary ref
544 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
545 // Now we rename also files into index
546 $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)."'";
547 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
548 $resql = $this->db->query($sql);
549 if (!$resql) {
550 $error++;
551 $this->error = $this->db->lasterror();
552 }
553 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skilldet/".$this->db->escape($this->newref)."'";
554 $sql .= " WHERE filepath = 'skilldet/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
555 $resql = $this->db->query($sql);
556 if (!$resql) {
557 $error++;
558 $this->error = $this->db->lasterror();
559 }
560
561 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
562 $oldref = dol_sanitizeFileName($this->ref);
563 $newref = dol_sanitizeFileName($num);
564 $dirsource = $conf->hrm->dir_output.'/skilldet/'.$oldref;
565 $dirdest = $conf->hrm->dir_output.'/skilldet/'.$newref;
566 if (!$error && file_exists($dirsource)) {
567 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
568
569 if (@rename($dirsource, $dirdest)) {
570 dol_syslog("Rename ok");
571 // Rename docs starting with $oldref with $newref
572 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skilldet/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
573 foreach ($listoffiles as $fileentry) {
574 $dirsource = $fileentry['name'];
575 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
576 $dirsource = $fileentry['path'].'/'.$dirsource;
577 $dirdest = $fileentry['path'].'/'.$dirdest;
578 @rename($dirsource, $dirdest);
579 }
580 }
581 }
582 }
583 }
584
585 // Set new ref and current status
586 if (!$error) {
587 $this->ref = $num;
588 $this->status = self::STATUS_VALIDATED;
589 }
590
591 if (!$error) {
592 $this->db->commit();
593 return 1;
594 } else {
595 $this->db->rollback();
596 return -1;
597 }
598 }
599
600
608 public function setDraft($user, $notrigger = 0)
609 {
610 // Protection
611 if ($this->status <= self::STATUS_DRAFT) {
612 return 0;
613 }
614
615 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
616 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
617 {
618 $this->error='Permission denied';
619 return -1;
620 }*/
621
622 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLDET_UNVALIDATE');
623 }
624
632 public function cancel($user, $notrigger = 0)
633 {
634 // Protection
635 if ($this->status != self::STATUS_VALIDATED) {
636 return 0;
637 }
638
639 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
640 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
641 {
642 $this->error='Permission denied';
643 return -1;
644 }*/
645
646 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLDET_CANCEL');
647 }
648
656 public function reopen($user, $notrigger = 0)
657 {
658 // Protection
659 if ($this->status != self::STATUS_CANCELED) {
660 return 0;
661 }
662
663 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
664 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
665 {
666 $this->error='Permission denied';
667 return -1;
668 }*/
669
670 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLDET_REOPEN');
671 }
672
683 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
684 {
685 global $conf, $langs, $hookmanager;
686
687 if (!empty($conf->dol_no_mouse_hover)) {
688 $notooltip = 1; // Force disable tooltips
689 }
690
691 $result = '';
692
693 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Skilldet").'</u>';
694 if (isset($this->status)) {
695 $label .= ' '.$this->getLibStatut(5);
696 }
697 $label .= '<br>';
698 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
699
700 $url = dol_buildpath('/hrm/skilldet_card.php', 1).'?id='.$this->id;
701
702 if ($option != 'nolink') {
703 // Add param to save lastsearch_values or not
704 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
705 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
706 $add_save_lastsearch_values = 1;
707 }
708 if ($add_save_lastsearch_values) {
709 $url .= '&save_lastsearch_values=1';
710 }
711 }
712
713 $linkclose = '';
714 if (empty($notooltip)) {
715 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
716 $label = $langs->trans("ShowSkilldet");
717 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
718 }
719 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
720 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
721 } else {
722 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
723 }
724
725 if ($option == 'nolink') {
726 $linkstart = '<span';
727 } else {
728 $linkstart = '<a href="'.$url.'"';
729 }
730 $linkstart .= $linkclose.'>';
731 if ($option == 'nolink') {
732 $linkend = '</span>';
733 } else {
734 $linkend = '</a>';
735 }
736
737 $result .= $linkstart;
738
739 if (empty($this->showphoto_on_popup)) {
740 if ($withpicto) {
741 $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);
742 }
743 } else {
744 if ($withpicto) {
745 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
746
747 list($class, $module) = explode('@', $this->picto);
748 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
749 $filearray = dol_dir_list($upload_dir, "files");
750 $filename = $filearray[0]['name'];
751 if (!empty($filename)) {
752 $pospoint = strpos($filearray[0]['name'], '.');
753
754 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
755 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
756 $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>';
757 } else {
758 $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>';
759 }
760
761 $result .= '</div>';
762 } else {
763 $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);
764 }
765 }
766 }
767
768 if ($withpicto != 2) {
769 $result .= $this->ref;
770 }
771
772 $result .= $linkend;
773 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
774
775 global $action, $hookmanager;
776 $hookmanager->initHooks(array('skilldetdao'));
777 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
778 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
779 if ($reshook > 0) {
780 $result = $hookmanager->resPrint;
781 } else {
782 $result .= $hookmanager->resPrint;
783 }
784
785 return $result;
786 }
787
794 public function getLibStatut($mode = 0)
795 {
796 return $this->LibStatut($this->status, $mode);
797 }
798
799 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
807 public function LibStatut($status, $mode = 0)
808 {
809 // phpcs:enable
810 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
811 global $langs;
812 //$langs->load("hrm");
813 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
814 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
815 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
816 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
817 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
818 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
819 }
820
821 $statusType = 'status'.$status;
822 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
823 if ($status == self::STATUS_CANCELED) {
824 $statusType = 'status6';
825 }
826
827 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
828 }
829
836 public function info($id)
837 {
838 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
839 $sql .= ' fk_user_creat, fk_user_modif';
840 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
841 $sql .= ' WHERE t.rowid = '.((int) $id);
842 $result = $this->db->query($sql);
843 if ($result) {
844 if ($this->db->num_rows($result)) {
845 $obj = $this->db->fetch_object($result);
846
847 $this->id = $obj->rowid;
848
849 $this->user_creation_id = $obj->fk_user_creat;
850 $this->user_modification_id = $obj->fk_user_modif;
851 $this->date_creation = $this->db->jdate($obj->datec);
852 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
853 }
854
855 $this->db->free($result);
856 } else {
857 dol_print_error($this->db);
858 }
859 }
860
867 public function initAsSpecimen()
868 {
869 // Set here init that are not commonf fields
870 // $this->property1 = ...
871 // $this->property2 = ...
872
873 $this->initAsSpecimenCommon();
874 }
875
876
882 public function getNextNumRef()
883 {
884 global $langs, $conf;
885 $langs->load("hrm");
886
887 if (!getDolGlobalString('hrm_SKILLDET_ADDON')) {
888 $conf->global->hrm_SKILLDET_ADDON = 'mod_skilldet_standard';
889 }
890
891 if (getDolGlobalString('hrm_SKILLDET_ADDON')) {
892 $mybool = false;
893
894 $file = getDolGlobalString('hrm_SKILLDET_ADDON') . ".php";
895 $classname = $conf->global->hrm_SKILLDET_ADDON;
896
897 // Include file with class
898 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
899 foreach ($dirmodels as $reldir) {
900 $dir = dol_buildpath($reldir."core/modules/hrm/");
901
902 // Load file with numbering class (if found)
903 $mybool |= @include_once $dir.$file;
904 }
905
906 if ($mybool === false) {
907 dol_print_error('', "Failed to include file ".$file);
908 return '';
909 }
910
911 if (class_exists($classname)) {
912 $obj = new $classname();
913 $numref = $obj->getNextValue($this);
914
915 if ($numref != '' && $numref != '-1') {
916 return $numref;
917 } else {
918 $this->error = $obj->error;
919 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
920 return "";
921 }
922 } else {
923 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
924 return "";
925 }
926 } else {
927 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
928 return "";
929 }
930 }
931
943 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
944 {
945 global $conf, $langs;
946
947 $result = 0;
948 $includedocgeneration = 0;
949
950 $langs->load("hrm");
951
952 if (!dol_strlen($modele)) {
953 $modele = 'standard_skilldet';
954
955 if (!empty($this->model_pdf)) {
956 $modele = $this->model_pdf;
957 } elseif (getDolGlobalString('SKILLDET_ADDON_PDF')) {
958 $modele = $conf->global->SKILLDET_ADDON_PDF;
959 }
960 }
961
962 $modelpath = "core/modules/hrm/doc/";
963
964 if ($includedocgeneration && !empty($modele)) {
965 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
966 }
967
968 return $result;
969 }
970
978 public function doScheduledJob()
979 {
980 global $conf, $langs;
981
982 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
983
984 $error = 0;
985 $this->output = '';
986 $this->error = '';
987
988 dol_syslog(__METHOD__, LOG_DEBUG);
989
990 $now = dol_now();
991
992 $this->db->begin();
993
994 // ...
995
996 $this->db->commit();
997
998 return $error;
999 }
1000}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
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.
update(User $user, $notrigger=false)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
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 optionaly the picto)
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
fetchLines()
Load object lines in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
deleteLine(User $user, $idline, $notrigger=false)
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.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
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($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.