dolibarr 23.0.3
skillrank.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-2025 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';
32require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skillrank.lib.php';
33
38{
42 public $module = 'hrm';
43
47 public $element = 'skillrank';
48
52 public $table_element = 'hrm_skillrank';
53
57 public $picto = 'skillrank@hrm';
58
59
60 const STATUS_DRAFT = 0;
61 const STATUS_VALIDATED = 1;
62 const STATUS_CANCELED = 9;
63
64 const SKILLRANK_TYPE_JOB = "job";
65 const SKILLRANK_TYPE_USER = "user";
66 const SKILLRANK_TYPE_EVALDET = "evaluationdet";
67
94 // BEGIN MODULEBUILDER PROPERTIES
98 public $fields = array(
99 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
100 'fk_skill' => array('type' => 'integer:Skill:hrm/class/skill.class.php:1', 'label' => 'Skill', 'enabled' => 1, 'position' => 3, 'notnull' => 1, 'visible' => 1, 'index' => 1,),
101 'rankorder' => array('type' => 'integer', 'label' => 'Rank', 'enabled' => 1, 'position' => 4, 'notnull' => 1, 'visible' => 1, 'default' => '0'),
102 'fk_object' => array('type' => 'integer', 'label' => 'object', 'enabled' => 1, 'position' => 5, 'notnull' => 1, 'visible' => 0,),
103 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
104 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
105 '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',),
106 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
107 'objecttype' => array('type' => 'varchar(128)', 'label' => 'objecttype', 'enabled' => 1, 'position' => 6, 'notnull' => 1, 'visible' => 0,),
108 );
112 public $rowid;
116 public $fk_skill;
120 public $rank;
124 public $fk_object;
128 public $fk_user_creat;
132 public $fk_user_modif;
136 public $objecttype;
137 // END MODULEBUILDER PROPERTIES
141 public $rankorder;
142
148 public function __construct(DoliDB $db)
149 {
150 global $conf, $langs;
151
152 $this->db = $db;
153
154 $this->ismultientitymanaged = 0;
155 $this->isextrafieldmanaged = 0;
156
157 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
158 $this->fields['rowid']['visible'] = 0;
159 }
160 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
161 $this->fields['entity']['enabled'] = 0;
162 }
163
164 // Example to show how to set values of fields definition dynamically
165 /*if ($user->rights->hrm->skillrank->read) {
166 $this->fields['myfield']['visible'] = 1;
167 $this->fields['myfield']['noteditable'] = 0;
168 }*/
169
170 // Unset fields that are disabled
171 foreach ($this->fields as $key => $val) {
172 if (isset($val['enabled']) && empty($val['enabled'])) {
173 unset($this->fields[$key]);
174 }
175 }
176
177 // Translate some data of arrayofkeyval
178 if (is_object($langs)) {
179 foreach ($this->fields as $key => $val) {
180 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
181 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
182 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
183 }
184 }
185 }
186 }
187 }
188
196 public function create(User $user, $notrigger = 0)
197 {
198 global $langs;
199
200 $filter = '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")";
201
202 $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, $filter);
203 if (!empty($alreadyLinked)) {
204 $this->error = $langs->trans('ErrSkillAlreadyAdded');
205 return -1;
206 }
207
208 $resultcreate = $this->createCommon($user, $notrigger);
209
210 return $resultcreate;
211 }
212
221 public function createFromClone(User $user, $fromid, $fk_object = 0)
222 {
223 global $langs, $extrafields;
224 $error = 0;
225
226 dol_syslog(__METHOD__, LOG_DEBUG);
227
228 $object = new self($this->db);
229
230 $this->db->begin();
231
232 // Load source object
233 $result = $object->fetchCommon($fromid);
234 if ($result > 0 && !empty($object->table_element_line)) {
235 $object->fetchLines();
236 }
237
238 // get lines so they will be clone
239 //foreach($this->lines as $line)
240 // $line->fetch_optionals();
241
242 // Reset some properties
243 unset($object->id);
244 unset($object->fk_user_creat);
245 unset($object->user_creation_id);
246 unset($object->import_key);
247 if (!empty($fk_object) && $fk_object > 0) {
248 unset($object->fk_object);
249 }
250
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, 'status')) {
257 $object->status = self::STATUS_DRAFT;
258 }
259 if (property_exists($object, 'date_creation')) {
260 $object->date_creation = dol_now();
261 }
262 if (property_exists($object, 'date_modification')) {
263 $object->date_modification = null;
264 }
265 if (!empty($fk_object) && $fk_object > 0) {
266 if (property_exists($object, 'fk_object')) {
267 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
268 }
269 }
270 // ...
271 // Clear extrafields that are unique
272 if (is_array($object->array_options) && count($object->array_options) > 0) {
273 $extrafields->fetch_name_optionals_label($this->table_element);
274 foreach ($object->array_options as $key => $option) {
275 $shortkey = preg_replace('/options_/', '', $key);
276 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
277 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
278 unset($object->array_options[$key]);
279 }
280 }
281 }
282
283 // Create clone
284 $object->context['createfromclone'] = 'createfromclone';
285 $result = $object->createCommon($user);
286 if ($result < 0) {
287 $error++;
289 }
290
291 if (!$error) {
292 // copy internal contacts
293 if ($this->copy_linked_contact($object, 'internal') < 0) {
294 $error++;
295 }
296 }
297
298 if (!$error) {
299 // copy external contacts if same company
300 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
301 if ($this->copy_linked_contact($object, 'external') < 0) {
302 $error++;
303 }
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
356 public function cloneFromCurrentSkill($currentSkill, $fk_user)
357 {
358 global $user;
359
360 $this->fk_skill = $currentSkill->fk_skill;
361 $this->rankorder = $currentSkill->rankorder;
362 $this->fk_object = $fk_user;
363 $this->date_creation = dol_now();
364 $this->fk_user_creat = $user->id;
365 $this->fk_user_modif = $user->id;
366 $this->objecttype = self::SKILLRANK_TYPE_USER;
367 $result = $this->create($user);
368
369 return $result;
370 }
371
384 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
385 {
386 dol_syslog(__METHOD__, LOG_DEBUG);
387
388 $records = array();
389
390 $sql = 'SELECT ';
391 $sql .= $this->getFieldList('t');
392 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
393 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
394 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
395 } else {
396 $sql .= ' WHERE 1 = 1';
397 }
398
399 // Manage filter
400 $errormessage = '';
401 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
402 if ($errormessage) {
403 $this->errors[] = $errormessage;
404 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
405 return -1;
406 }
407
408 if (!empty($sortfield)) {
409 $sql .= $this->db->order($sortfield, $sortorder);
410 }
411 if (!empty($limit)) {
412 $sql .= ' '.$this->db->plimit($limit, $offset);
413 }
414
415 $resql = $this->db->query($sql);
416 if ($resql) {
417 $num = $this->db->num_rows($resql);
418 $i = 0;
419 while ($i < ($limit ? min($limit, $num) : $num)) {
420 $obj = $this->db->fetch_object($resql);
421
422 $record = new self($this->db);
423 $record->setVarsFromFetchObj($obj);
424
425 $records[$record->id] = $record;
426
427 $i++;
428 }
429 $this->db->free($resql);
430
431 return $records;
432 } else {
433 $this->errors[] = 'Error '.$this->db->lasterror();
434 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
435
436 return -1;
437 }
438 }
439
447 public function update(User $user, $notrigger = 0)
448 {
449 return $this->updateCommon($user, $notrigger);
450 }
451
459 public function delete(User $user, $notrigger = 0)
460 {
461 return $this->deleteCommon($user, $notrigger);
462 //return $this->deleteCommon($user, $notrigger, 1);
463 }
464
473 public function deleteLine(User $user, $idline, $notrigger = 0)
474 {
475 if ($this->status < 0) {
476 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
477 return -2;
478 }
479
480 return $this->deleteLineCommon($user, $idline, $notrigger);
481 }
482
483
491 public function validate($user, $notrigger = 0)
492 {
493 global $conf, $langs;
494
495 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
496
497 $error = 0;
498
499 // Protection
500 if ($this->status == self::STATUS_VALIDATED) {
501 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
502 return 0;
503 }
504
505 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->write))
506 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
507 {
508 $this->error='NotEnoughPermissions';
509 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
510 return -1;
511 }*/
512
513 $now = dol_now();
514
515 $this->db->begin();
516
517 // Define new ref
518 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
519 $num = $this->getNextNumRef();
520 } else {
521 $num = (string) $this->ref;
522 }
523 $this->newref = $num;
524
525 if (!empty($num)) {
526 // Validate
527 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
528 $sql .= " SET ref = '".$this->db->escape($num)."',";
529 $sql .= " status = ".self::STATUS_VALIDATED;
530 if (!empty($this->fields['date_validation'])) {
531 $sql .= ", date_validation = '".$this->db->idate($now)."'";
532 }
533 if (!empty($this->fields['fk_user_valid'])) {
534 $sql .= ", fk_user_valid = ".((int) $user->id);
535 }
536 $sql .= " WHERE rowid = ".((int) $this->id);
537
538 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
539 $resql = $this->db->query($sql);
540 if (!$resql) {
541 dol_print_error($this->db);
542 $this->error = $this->db->lasterror();
543 $error++;
544 }
545
546 if (!$error && !$notrigger) {
547 // Call trigger
548 $result = $this->call_trigger('HRM_SKILLRANK_VALIDATE', $user);
549 if ($result < 0) {
550 $error++;
551 }
552 // End call triggers
553 }
554 }
555
556 if (!$error) {
557 $this->oldref = $this->ref;
558
559 // Rename directory if dir was a temporary ref
560 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
561 // Now we rename also files into index
562 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'skillrank/".$this->db->escape($this->newref)."'";
563 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
564 $resql = $this->db->query($sql);
565 if (!$resql) {
566 $error++;
567 $this->error = $this->db->lasterror();
568 }
569 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
570 $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
571 $resql = $this->db->query($sql);
572 if (!$resql) {
573 $error++;
574 $this->error = $this->db->lasterror();
575 }
576
577 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
578 $oldref = dol_sanitizeFileName($this->ref);
579 $newref = dol_sanitizeFileName($num);
580 $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
581 $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
582 if (!$error && file_exists($dirsource)) {
583 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
584
585 if (@rename($dirsource, $dirdest)) {
586 dol_syslog("Rename ok");
587 // Rename docs starting with $oldref with $newref
588 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
589 foreach ($listoffiles as $fileentry) {
590 $dirsource = $fileentry['name'];
591 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
592 $dirsource = $fileentry['path'].'/'.$dirsource;
593 $dirdest = $fileentry['path'].'/'.$dirdest;
594 @rename($dirsource, $dirdest);
595 }
596 }
597 }
598 }
599 }
600
601 // Set new ref and current status
602 if (!$error) {
603 $this->ref = $num;
604 $this->status = self::STATUS_VALIDATED;
605 }
606
607 if (!$error) {
608 $this->db->commit();
609 return 1;
610 } else {
611 $this->db->rollback();
612 return -1;
613 }
614 }
615
616
624 public function setDraft($user, $notrigger = 0)
625 {
626 // Protection
627 if ($this->status <= self::STATUS_DRAFT) {
628 return 0;
629 }
630
631 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
632 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
633 {
634 $this->error='Permission denied';
635 return -1;
636 }*/
637
638 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
639 }
640
648 public function cancel($user, $notrigger = 0)
649 {
650 // Protection
651 if ($this->status != self::STATUS_VALIDATED) {
652 return 0;
653 }
654
655 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
656 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
657 {
658 $this->error='Permission denied';
659 return -1;
660 }*/
661
662 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
663 }
664
672 public function reopen($user, $notrigger = 0)
673 {
674 // Protection
675 if ($this->status != self::STATUS_CANCELED) {
676 return 0;
677 }
678
679 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
680 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
681 {
682 $this->error='Permission denied';
683 return -1;
684 }*/
685
686 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
687 }
688
699 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
700 {
701 global $conf, $langs, $hookmanager;
702
703 if (!empty($conf->dol_no_mouse_hover)) {
704 $notooltip = 1; // Force disable tooltips
705 }
706
707 $result = '';
708
709 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
710 if (isset($this->status)) {
711 $label .= ' '.$this->getLibStatut(5);
712 }
713 $label .= '<br>';
714 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
715
716 $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
717
718 if ($option != 'nolink') {
719 // Add param to save lastsearch_values or not
720 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
721 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
722 $add_save_lastsearch_values = 1;
723 }
724 if ($add_save_lastsearch_values) {
725 $url .= '&save_lastsearch_values=1';
726 }
727 }
728
729 $linkclose = '';
730 if (empty($notooltip)) {
731 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
732 $label = $langs->trans("ShowSkillRank");
733 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
734 }
735 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
736 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
737 } else {
738 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
739 }
740
741 if ($option == 'nolink') {
742 $linkstart = '<span';
743 } else {
744 $linkstart = '<a href="'.$url.'"';
745 }
746 $linkstart .= $linkclose.'>';
747 if ($option == 'nolink') {
748 $linkend = '</span>';
749 } else {
750 $linkend = '</a>';
751 }
752
753 $result .= $linkstart;
754
755 if (empty($this->showphoto_on_popup)) {
756 if ($withpicto) {
757 $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);
758 }
759 } else {
760 if ($withpicto) {
761 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
762
763 list($class, $module) = explode('@', $this->picto);
764 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
765 $filearray = dol_dir_list($upload_dir, "files");
766 $filename = $filearray[0]['name'];
767 if (!empty($filename)) {
768 $pospoint = strpos($filearray[0]['name'], '.');
769
770 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
771 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
772 $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>';
773 } else {
774 $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>';
775 }
776
777 $result .= '</div>';
778 } else {
779 $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);
780 }
781 }
782 }
783
784 if ($withpicto != 2) {
785 $result .= $this->ref;
786 }
787
788 $result .= $linkend;
789 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
790
791 global $action, $hookmanager;
792 $hookmanager->initHooks(array('skillrankdao'));
793 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
794 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
795 if ($reshook > 0) {
796 $result = $hookmanager->resPrint;
797 } else {
798 $result .= $hookmanager->resPrint;
799 }
800
801 return $result;
802 }
803
810 public function getLibStatut($mode = 0)
811 {
812 return $this->LibStatut($this->status, $mode);
813 }
814
815 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
823 public function LibStatut($status, $mode = 0)
824 {
825 // phpcs:enable
826 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
827 global $langs;
828 //$langs->load("hrm");
829 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
830 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
831 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
832 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
833 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
834 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
835 }
836
837 $statusType = 'status'.$status;
838 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
839 if ($status == self::STATUS_CANCELED) {
840 $statusType = 'status6';
841 }
842
843 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
844 }
845
852 public function info($id)
853 {
854 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
855 $sql .= ' fk_user_creat, fk_user_modif';
856 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
857 $sql .= ' WHERE t.rowid = '.((int) $id);
858 $result = $this->db->query($sql);
859 if ($result) {
860 if ($this->db->num_rows($result)) {
861 $obj = $this->db->fetch_object($result);
862
863 $this->id = $obj->rowid;
864
865 $this->user_creation_id = $obj->fk_user_creat;
866 $this->user_modification_id = $obj->fk_user_modif;
867 $this->date_creation = $this->db->jdate($obj->datec);
868 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
869 }
870
871 $this->db->free($result);
872 } else {
873 dol_print_error($this->db);
874 }
875 }
876
883 public function initAsSpecimen()
884 {
885 // Set here init that are not commonf fields
886 // $this->property1 = ...
887 // $this->property2 = ...
888
889 return $this->initAsSpecimenCommon();
890 }
891
897 public function getLinesArray()
898 {
899 $this->lines = array();
900
901 /*
902 $objectline = new SkillRankLine($this->db);
903 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_skillrank:=:'.((int) $this->id).')');
904
905 if (is_numeric($result)) {
906 $this->error = $objectline->error;
907 $this->errors = $objectline->errors;
908 return $result;
909 } else {
910 $this->lines = $result;
911 return $this->lines;
912 }
913 */
914
915 return $this->lines;
916 }
917
923 public function getNextNumRef()
924 {
925 global $langs, $conf;
926 $langs->load("hrm");
927
928 if (!getDolGlobalString('hrm_SKILLRANK_ADDON')) {
929 $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
930 }
931
932 if (getDolGlobalString('hrm_SKILLRANK_ADDON')) {
933 $mybool = false;
934
935 $file = getDolGlobalString('hrm_SKILLRANK_ADDON') . ".php";
936 $classname = getDolGlobalString('hrm_SKILLRANK_ADDON');
937
938 // Include file with class
939 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
940 foreach ($dirmodels as $reldir) {
941 $dir = dol_buildpath($reldir."core/modules/hrm/");
942
943 // Load file with numbering class (if found)
944 $mybool = ((bool) @include_once $dir.$file) || $mybool;
945 }
946
947 if (!$mybool) {
948 dol_print_error(null, "Failed to include file ".$file);
949 return '';
950 }
951
952 if (class_exists($classname)) {
953 $obj = new $classname();
954 '@phan-var-force ModeleNumRefEvaluation $obj';
956 $numref = $obj->getNextValue($this);
957
958 if ($numref != '' && $numref != '-1') {
959 return $numref;
960 } else {
961 $this->error = $obj->error;
962 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
963 return "";
964 }
965 } else {
966 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
967 return "";
968 }
969 } else {
970 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
971 return "";
972 }
973 }
974
986 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
987 {
988 global $conf, $langs;
989
990 $result = 0;
991 $includedocgeneration = 0;
992
993 $langs->load("hrm");
994
995 if (!dol_strlen($modele)) {
996 $modele = 'standard_skillrank';
997
998 if (!empty($this->model_pdf)) {
999 $modele = $this->model_pdf;
1000 } elseif (getDolGlobalString('SKILLRANK_ADDON_PDF')) {
1001 $modele = getDolGlobalString('SKILLRANK_ADDON_PDF');
1002 }
1003 }
1004
1005 $modelpath = "core/modules/hrm/doc/";
1006
1007 if ($includedocgeneration && !empty($modele)) {
1008 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1009 }
1010
1011 return $result;
1012 }
1013}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
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.
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.
Class to manage Dolibarr database access.
Class for SkillRank.
reopen($user, $notrigger=0)
Set back to validated status.
__construct(DoliDB $db)
Constructor.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
LibStatut($status, $mode=0)
Return the status.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
setDraft($user, $notrigger=0)
Set draft status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetchLines()
Load object lines in memory from the database.
fetch($id, $ref=null)
Load object in memory from the database.
cloneFromCurrentSkill($currentSkill, $fk_user)
Clone skillrank Object linked to job with user id The skillrank table is a join table that is marked ...
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
createFromClone(User $user, $fromid, $fk_object=0)
Clone an object into another one.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
validate($user, $notrigger=0)
Validate object.
getLibStatut($mode=0)
Return the label of the status.
cancel($user, $notrigger=0)
Set cancel status.
getLinesArray()
Create an array of lines.
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:171
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:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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 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.