dolibarr 20.0.0
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 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
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 );
109 public $rowid;
110 public $fk_skill;
111 public $rank;
112 public $fk_object;
113 public $date_creation;
114 public $fk_user_creat;
115 public $fk_user_modif;
116 public $objecttype;
117 // END MODULEBUILDER PROPERTIES
118 public $rankorder;
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_skillrankline';
127
128 // /**
129 // * @var string Field with ID of parent key if this object has a parent
130 // */
131 // public $fk_element = 'fk_skillrank';
132
133 // /**
134 // * @var string Name of subtable class that manage subtable lines
135 // */
136 // public $class_element_line = 'SkillRankline';
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_skillrankdet');
149
150 // /**
151 // * @var SkillRankLine[] 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 = 0;
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->skillrank->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 global $langs;
213
214 $filter = '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")";
215
216 $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, $filter);
217 if (!empty($alreadyLinked)) {
218 $this->error = $langs->trans('ErrSkillAlreadyAdded');
219 return -1;
220 }
221
222 $resultcreate = $this->createCommon($user, $notrigger);
223
224 return $resultcreate;
225 }
226
235 public function createFromClone(User $user, $fromid, $fk_object = 0)
236 {
237 global $langs, $extrafields;
238 $error = 0;
239
240 dol_syslog(__METHOD__, LOG_DEBUG);
241
242 $object = new self($this->db);
243
244 $this->db->begin();
245
246 // Load source object
247 $result = $object->fetchCommon($fromid);
248 if ($result > 0 && !empty($object->table_element_line)) {
249 $object->fetchLines();
250 }
251
252 // get lines so they will be clone
253 //foreach($this->lines as $line)
254 // $line->fetch_optionals();
255
256 // Reset some properties
257 unset($object->id);
258 unset($object->fk_user_creat);
259 unset($object->import_key);
260 if (!empty($fk_object) && $fk_object > 0) {
261 unset($object->fk_object);
262 }
263
264
265 // Clear fields
266 if (property_exists($object, 'ref')) {
267 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
268 }
269 if (property_exists($object, 'label')) {
270 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
271 }
272 if (property_exists($object, 'status')) {
273 $object->status = self::STATUS_DRAFT;
274 }
275 if (property_exists($object, 'date_creation')) {
276 $object->date_creation = dol_now();
277 }
278 if (property_exists($object, 'date_modification')) {
279 $object->date_modification = null;
280 }
281 if (!empty($fk_object) && $fk_object > 0) {
282 if (property_exists($object, 'fk_object')) {
283 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
284 }
285 }
286 // ...
287 // Clear extrafields that are unique
288 if (is_array($object->array_options) && count($object->array_options) > 0) {
289 $extrafields->fetch_name_optionals_label($this->table_element);
290 foreach ($object->array_options as $key => $option) {
291 $shortkey = preg_replace('/options_/', '', $key);
292 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
293 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
294 unset($object->array_options[$key]);
295 }
296 }
297 }
298
299 // Create clone
300 $object->context['createfromclone'] = 'createfromclone';
301 $result = $object->createCommon($user);
302 if ($result < 0) {
303 $error++;
305 }
306
307 if (!$error) {
308 // copy internal contacts
309 if ($this->copy_linked_contact($object, 'internal') < 0) {
310 $error++;
311 }
312 }
313
314 if (!$error) {
315 // copy external contacts if same company
316 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
317 if ($this->copy_linked_contact($object, 'external') < 0) {
318 $error++;
319 }
320 }
321 }
322
323 unset($object->context['createfromclone']);
324
325 // End
326 if (!$error) {
327 $this->db->commit();
328 return $object;
329 } else {
330 $this->db->rollback();
331 return -1;
332 }
333 }
334
342 public function fetch($id, $ref = null)
343 {
344 $result = $this->fetchCommon($id, $ref);
345 if ($result > 0 && !empty($this->table_element_line)) {
346 $this->fetchLines();
347 }
348 return $result;
349 }
350
356 public function fetchLines()
357 {
358 $this->lines = array();
359
360 $result = $this->fetchLinesCommon();
361 return $result;
362 }
363
372 public function cloneFromCurrentSkill($currentSkill, $fk_user)
373 {
374 global $user;
375
376 $this->fk_skill = $currentSkill->fk_skill;
377 $this->rankorder = $currentSkill->rankorder;
378 $this->fk_object = $fk_user;
379 $this->date_creation = dol_now();
380 $this->fk_user_creat = $user->id;
381 $this->fk_user_modif = $user->id;
382 $this->objecttype = self::SKILLRANK_TYPE_USER;
383 $result = $this->create($user);
384
385 return $result;
386 }
387
400 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
401 {
402 dol_syslog(__METHOD__, LOG_DEBUG);
403
404 $records = array();
405
406 $sql = 'SELECT ';
407 $sql .= $this->getFieldList('t');
408 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
409 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
410 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
411 } else {
412 $sql .= ' WHERE 1 = 1';
413 }
414
415 // Manage filter
416 $errormessage = '';
417 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
418 if ($errormessage) {
419 $this->errors[] = $errormessage;
420 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
421 return -1;
422 }
423
424 if (!empty($sortfield)) {
425 $sql .= $this->db->order($sortfield, $sortorder);
426 }
427 if (!empty($limit)) {
428 $sql .= ' '.$this->db->plimit($limit, $offset);
429 }
430
431 $resql = $this->db->query($sql);
432 if ($resql) {
433 $num = $this->db->num_rows($resql);
434 $i = 0;
435 while ($i < ($limit ? min($limit, $num) : $num)) {
436 $obj = $this->db->fetch_object($resql);
437
438 $record = new self($this->db);
439 $record->setVarsFromFetchObj($obj);
440
441 $records[$record->id] = $record;
442
443 $i++;
444 }
445 $this->db->free($resql);
446
447 return $records;
448 } else {
449 $this->errors[] = 'Error '.$this->db->lasterror();
450 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
451
452 return -1;
453 }
454 }
455
463 public function update(User $user, $notrigger = 0)
464 {
465 return $this->updateCommon($user, $notrigger);
466 }
467
475 public function delete(User $user, $notrigger = 0)
476 {
477 return $this->deleteCommon($user, $notrigger);
478 //return $this->deleteCommon($user, $notrigger, 1);
479 }
480
489 public function deleteLine(User $user, $idline, $notrigger = 0)
490 {
491 if ($this->status < 0) {
492 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
493 return -2;
494 }
495
496 return $this->deleteLineCommon($user, $idline, $notrigger);
497 }
498
499
507 public function validate($user, $notrigger = 0)
508 {
509 global $conf, $langs;
510
511 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
512
513 $error = 0;
514
515 // Protection
516 if ($this->status == self::STATUS_VALIDATED) {
517 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
518 return 0;
519 }
520
521 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->write))
522 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
523 {
524 $this->error='NotEnoughPermissions';
525 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
526 return -1;
527 }*/
528
529 $now = dol_now();
530
531 $this->db->begin();
532
533 // Define new ref
534 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
535 $num = $this->getNextNumRef();
536 } else {
537 $num = $this->ref;
538 }
539 $this->newref = $num;
540
541 if (!empty($num)) {
542 // Validate
543 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
544 $sql .= " SET ref = '".$this->db->escape($num)."',";
545 $sql .= " status = ".self::STATUS_VALIDATED;
546 if (!empty($this->fields['date_validation'])) {
547 $sql .= ", date_validation = '".$this->db->idate($now)."'";
548 }
549 if (!empty($this->fields['fk_user_valid'])) {
550 $sql .= ", fk_user_valid = ".((int) $user->id);
551 }
552 $sql .= " WHERE rowid = ".((int) $this->id);
553
554 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
555 $resql = $this->db->query($sql);
556 if (!$resql) {
557 dol_print_error($this->db);
558 $this->error = $this->db->lasterror();
559 $error++;
560 }
561
562 if (!$error && !$notrigger) {
563 // Call trigger
564 $result = $this->call_trigger('HRM_SKILLRANK_VALIDATE', $user);
565 if ($result < 0) {
566 $error++;
567 }
568 // End call triggers
569 }
570 }
571
572 if (!$error) {
573 $this->oldref = $this->ref;
574
575 // Rename directory if dir was a temporary ref
576 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
577 // Now we rename also files into index
578 $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)."'";
579 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
580 $resql = $this->db->query($sql);
581 if (!$resql) {
582 $error++;
583 $this->error = $this->db->lasterror();
584 }
585 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
586 $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
587 $resql = $this->db->query($sql);
588 if (!$resql) {
589 $error++;
590 $this->error = $this->db->lasterror();
591 }
592
593 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
594 $oldref = dol_sanitizeFileName($this->ref);
595 $newref = dol_sanitizeFileName($num);
596 $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
597 $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
598 if (!$error && file_exists($dirsource)) {
599 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
600
601 if (@rename($dirsource, $dirdest)) {
602 dol_syslog("Rename ok");
603 // Rename docs starting with $oldref with $newref
604 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
605 foreach ($listoffiles as $fileentry) {
606 $dirsource = $fileentry['name'];
607 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
608 $dirsource = $fileentry['path'].'/'.$dirsource;
609 $dirdest = $fileentry['path'].'/'.$dirdest;
610 @rename($dirsource, $dirdest);
611 }
612 }
613 }
614 }
615 }
616
617 // Set new ref and current status
618 if (!$error) {
619 $this->ref = $num;
620 $this->status = self::STATUS_VALIDATED;
621 }
622
623 if (!$error) {
624 $this->db->commit();
625 return 1;
626 } else {
627 $this->db->rollback();
628 return -1;
629 }
630 }
631
632
640 public function setDraft($user, $notrigger = 0)
641 {
642 // Protection
643 if ($this->status <= self::STATUS_DRAFT) {
644 return 0;
645 }
646
647 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
648 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
649 {
650 $this->error='Permission denied';
651 return -1;
652 }*/
653
654 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
655 }
656
664 public function cancel($user, $notrigger = 0)
665 {
666 // Protection
667 if ($this->status != self::STATUS_VALIDATED) {
668 return 0;
669 }
670
671 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
672 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
673 {
674 $this->error='Permission denied';
675 return -1;
676 }*/
677
678 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
679 }
680
688 public function reopen($user, $notrigger = 0)
689 {
690 // Protection
691 if ($this->status != self::STATUS_CANCELED) {
692 return 0;
693 }
694
695 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
696 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
697 {
698 $this->error='Permission denied';
699 return -1;
700 }*/
701
702 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
703 }
704
715 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
716 {
717 global $conf, $langs, $hookmanager;
718
719 if (!empty($conf->dol_no_mouse_hover)) {
720 $notooltip = 1; // Force disable tooltips
721 }
722
723 $result = '';
724
725 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
726 if (isset($this->status)) {
727 $label .= ' '.$this->getLibStatut(5);
728 }
729 $label .= '<br>';
730 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
731
732 $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
733
734 if ($option != 'nolink') {
735 // Add param to save lastsearch_values or not
736 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
737 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
738 $add_save_lastsearch_values = 1;
739 }
740 if ($add_save_lastsearch_values) {
741 $url .= '&save_lastsearch_values=1';
742 }
743 }
744
745 $linkclose = '';
746 if (empty($notooltip)) {
747 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
748 $label = $langs->trans("ShowSkillRank");
749 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
750 }
751 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
752 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
753 } else {
754 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
755 }
756
757 if ($option == 'nolink') {
758 $linkstart = '<span';
759 } else {
760 $linkstart = '<a href="'.$url.'"';
761 }
762 $linkstart .= $linkclose.'>';
763 if ($option == 'nolink') {
764 $linkend = '</span>';
765 } else {
766 $linkend = '</a>';
767 }
768
769 $result .= $linkstart;
770
771 if (empty($this->showphoto_on_popup)) {
772 if ($withpicto) {
773 $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);
774 }
775 } else {
776 if ($withpicto) {
777 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
778
779 list($class, $module) = explode('@', $this->picto);
780 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
781 $filearray = dol_dir_list($upload_dir, "files");
782 $filename = $filearray[0]['name'];
783 if (!empty($filename)) {
784 $pospoint = strpos($filearray[0]['name'], '.');
785
786 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
787 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
788 $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>';
789 } else {
790 $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>';
791 }
792
793 $result .= '</div>';
794 } else {
795 $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);
796 }
797 }
798 }
799
800 if ($withpicto != 2) {
801 $result .= $this->ref;
802 }
803
804 $result .= $linkend;
805 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
806
807 global $action, $hookmanager;
808 $hookmanager->initHooks(array('skillrankdao'));
809 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
810 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
811 if ($reshook > 0) {
812 $result = $hookmanager->resPrint;
813 } else {
814 $result .= $hookmanager->resPrint;
815 }
816
817 return $result;
818 }
819
826 public function getLibStatut($mode = 0)
827 {
828 return $this->LibStatut($this->status, $mode);
829 }
830
831 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839 public function LibStatut($status, $mode = 0)
840 {
841 // phpcs:enable
842 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
843 global $langs;
844 //$langs->load("hrm");
845 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
846 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
847 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
848 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
849 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
850 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
851 }
852
853 $statusType = 'status'.$status;
854 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
855 if ($status == self::STATUS_CANCELED) {
856 $statusType = 'status6';
857 }
858
859 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
860 }
861
868 public function info($id)
869 {
870 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
871 $sql .= ' fk_user_creat, fk_user_modif';
872 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
873 $sql .= ' WHERE t.rowid = '.((int) $id);
874 $result = $this->db->query($sql);
875 if ($result) {
876 if ($this->db->num_rows($result)) {
877 $obj = $this->db->fetch_object($result);
878
879 $this->id = $obj->rowid;
880
881 $this->user_creation_id = $obj->fk_user_creat;
882 $this->user_modification_id = $obj->fk_user_modif;
883 $this->date_creation = $this->db->jdate($obj->datec);
884 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
885 }
886
887 $this->db->free($result);
888 } else {
889 dol_print_error($this->db);
890 }
891 }
892
899 public function initAsSpecimen()
900 {
901 // Set here init that are not commonf fields
902 // $this->property1 = ...
903 // $this->property2 = ...
904
905 return $this->initAsSpecimenCommon();
906 }
907
913 public function getLinesArray()
914 {
915 $this->lines = array();
916
917 /*
918 $objectline = new SkillRankLine($this->db);
919 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_skillrank:=:'.((int) $this->id).')');
920
921 if (is_numeric($result)) {
922 $this->error = $objectline->error;
923 $this->errors = $objectline->errors;
924 return $result;
925 } else {
926 $this->lines = $result;
927 return $this->lines;
928 }
929 */
930
931 return $this->lines;
932 }
933
939 public function getNextNumRef()
940 {
941 global $langs, $conf;
942 $langs->load("hrm");
943
944 if (!getDolGlobalString('hrm_SKILLRANK_ADDON')) {
945 $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
946 }
947
948 if (getDolGlobalString('hrm_SKILLRANK_ADDON')) {
949 $mybool = false;
950
951 $file = getDolGlobalString('hrm_SKILLRANK_ADDON') . ".php";
952 $classname = getDolGlobalString('hrm_SKILLRANK_ADDON');
953
954 // Include file with class
955 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
956 foreach ($dirmodels as $reldir) {
957 $dir = dol_buildpath($reldir."core/modules/hrm/");
958
959 // Load file with numbering class (if found)
960 $mybool = ((bool) @include_once $dir.$file) || $mybool;
961 }
962
963 if ($mybool === false) {
964 dol_print_error(null, "Failed to include file ".$file);
965 return '';
966 }
967
968 if (class_exists($classname)) {
969 $obj = new $classname();
970 $numref = $obj->getNextValue($this);
971
972 if ($numref != '' && $numref != '-1') {
973 return $numref;
974 } else {
975 $this->error = $obj->error;
976 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
977 return "";
978 }
979 } else {
980 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
981 return "";
982 }
983 } else {
984 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
985 return "";
986 }
987 }
988
1000 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1001 {
1002 global $conf, $langs;
1003
1004 $result = 0;
1005 $includedocgeneration = 0;
1006
1007 $langs->load("hrm");
1008
1009 if (!dol_strlen($modele)) {
1010 $modele = 'standard_skillrank';
1011
1012 if (!empty($this->model_pdf)) {
1013 $modele = $this->model_pdf;
1014 } elseif (getDolGlobalString('SKILLRANK_ADDON_PDF')) {
1015 $modele = getDolGlobalString('SKILLRANK_ADDON_PDF');
1016 }
1017 }
1018
1019 $modelpath = "core/modules/hrm/doc/";
1020
1021 if ($includedocgeneration && !empty($modele)) {
1022 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1023 }
1024
1025 return $result;
1026 }
1027}
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:636
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
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.
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.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
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.
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.