dolibarr 21.0.0-alpha
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 $fk_user_creat;
114 public $fk_user_modif;
115 public $objecttype;
116 // END MODULEBUILDER PROPERTIES
117 public $rankorder;
118
119
120 // If this object has a subtable with lines
121
122 // /**
123 // * @var string Name of subtable line
124 // */
125 // public $table_element_line = 'hrm_skillrankline';
126
127 // /**
128 // * @var string Field with ID of parent key if this object has a parent
129 // */
130 // public $fk_element = 'fk_skillrank';
131
132 // /**
133 // * @var string Name of subtable class that manage subtable lines
134 // */
135 // public $class_element_line = 'SkillRankline';
136
137 // /**
138 // * @var array List of child tables. To test if we can delete object.
139 // */
140 // protected $childtables = array();
141
142 // /**
143 // * @var array List of child tables. To know object to delete on cascade.
144 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
145 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
146 // */
147 // protected $childtablesoncascade = array('hrm_skillrankdet');
148
149 // /**
150 // * @var SkillRankLine[] Array of subtable lines
151 // */
152 // public $lines = array();
153
154
155
161 public function __construct(DoliDB $db)
162 {
163 global $conf, $langs;
164
165 $this->db = $db;
166
167 $this->ismultientitymanaged = 0;
168 $this->isextrafieldmanaged = 0;
169
170 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
171 $this->fields['rowid']['visible'] = 0;
172 }
173 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
174 $this->fields['entity']['enabled'] = 0;
175 }
176
177 // Example to show how to set values of fields definition dynamically
178 /*if ($user->rights->hrm->skillrank->read) {
179 $this->fields['myfield']['visible'] = 1;
180 $this->fields['myfield']['noteditable'] = 0;
181 }*/
182
183 // Unset fields that are disabled
184 foreach ($this->fields as $key => $val) {
185 if (isset($val['enabled']) && empty($val['enabled'])) {
186 unset($this->fields[$key]);
187 }
188 }
189
190 // Translate some data of arrayofkeyval
191 if (is_object($langs)) {
192 foreach ($this->fields as $key => $val) {
193 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
194 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
195 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
196 }
197 }
198 }
199 }
200 }
201
209 public function create(User $user, $notrigger = 0)
210 {
211 global $langs;
212
213 $filter = '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")";
214
215 $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, $filter);
216 if (!empty($alreadyLinked)) {
217 $this->error = $langs->trans('ErrSkillAlreadyAdded');
218 return -1;
219 }
220
221 $resultcreate = $this->createCommon($user, $notrigger);
222
223 return $resultcreate;
224 }
225
234 public function createFromClone(User $user, $fromid, $fk_object = 0)
235 {
236 global $langs, $extrafields;
237 $error = 0;
238
239 dol_syslog(__METHOD__, LOG_DEBUG);
240
241 $object = new self($this->db);
242
243 $this->db->begin();
244
245 // Load source object
246 $result = $object->fetchCommon($fromid);
247 if ($result > 0 && !empty($object->table_element_line)) {
248 $object->fetchLines();
249 }
250
251 // get lines so they will be clone
252 //foreach($this->lines as $line)
253 // $line->fetch_optionals();
254
255 // Reset some properties
256 unset($object->id);
257 unset($object->fk_user_creat);
258 unset($object->import_key);
259 if (!empty($fk_object) && $fk_object > 0) {
260 unset($object->fk_object);
261 }
262
263
264 // Clear fields
265 if (property_exists($object, 'ref')) {
266 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
267 }
268 if (property_exists($object, 'label')) {
269 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
270 }
271 if (property_exists($object, 'status')) {
272 $object->status = self::STATUS_DRAFT;
273 }
274 if (property_exists($object, 'date_creation')) {
275 $object->date_creation = dol_now();
276 }
277 if (property_exists($object, 'date_modification')) {
278 $object->date_modification = null;
279 }
280 if (!empty($fk_object) && $fk_object > 0) {
281 if (property_exists($object, 'fk_object')) {
282 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
283 }
284 }
285 // ...
286 // Clear extrafields that are unique
287 if (is_array($object->array_options) && count($object->array_options) > 0) {
288 $extrafields->fetch_name_optionals_label($this->table_element);
289 foreach ($object->array_options as $key => $option) {
290 $shortkey = preg_replace('/options_/', '', $key);
291 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
292 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
293 unset($object->array_options[$key]);
294 }
295 }
296 }
297
298 // Create clone
299 $object->context['createfromclone'] = 'createfromclone';
300 $result = $object->createCommon($user);
301 if ($result < 0) {
302 $error++;
304 }
305
306 if (!$error) {
307 // copy internal contacts
308 if ($this->copy_linked_contact($object, 'internal') < 0) {
309 $error++;
310 }
311 }
312
313 if (!$error) {
314 // copy external contacts if same company
315 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
316 if ($this->copy_linked_contact($object, 'external') < 0) {
317 $error++;
318 }
319 }
320 }
321
322 unset($object->context['createfromclone']);
323
324 // End
325 if (!$error) {
326 $this->db->commit();
327 return $object;
328 } else {
329 $this->db->rollback();
330 return -1;
331 }
332 }
333
341 public function fetch($id, $ref = null)
342 {
343 $result = $this->fetchCommon($id, $ref);
344 if ($result > 0 && !empty($this->table_element_line)) {
345 $this->fetchLines();
346 }
347 return $result;
348 }
349
355 public function fetchLines()
356 {
357 $this->lines = array();
358
359 $result = $this->fetchLinesCommon();
360 return $result;
361 }
362
371 public function cloneFromCurrentSkill($currentSkill, $fk_user)
372 {
373 global $user;
374
375 $this->fk_skill = $currentSkill->fk_skill;
376 $this->rankorder = $currentSkill->rankorder;
377 $this->fk_object = $fk_user;
378 $this->date_creation = dol_now();
379 $this->fk_user_creat = $user->id;
380 $this->fk_user_modif = $user->id;
381 $this->objecttype = self::SKILLRANK_TYPE_USER;
382 $result = $this->create($user);
383
384 return $result;
385 }
386
399 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
400 {
401 dol_syslog(__METHOD__, LOG_DEBUG);
402
403 $records = array();
404
405 $sql = 'SELECT ';
406 $sql .= $this->getFieldList('t');
407 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
408 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
409 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
410 } else {
411 $sql .= ' WHERE 1 = 1';
412 }
413
414 // Manage filter
415 $errormessage = '';
416 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
417 if ($errormessage) {
418 $this->errors[] = $errormessage;
419 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
420 return -1;
421 }
422
423 if (!empty($sortfield)) {
424 $sql .= $this->db->order($sortfield, $sortorder);
425 }
426 if (!empty($limit)) {
427 $sql .= ' '.$this->db->plimit($limit, $offset);
428 }
429
430 $resql = $this->db->query($sql);
431 if ($resql) {
432 $num = $this->db->num_rows($resql);
433 $i = 0;
434 while ($i < ($limit ? min($limit, $num) : $num)) {
435 $obj = $this->db->fetch_object($resql);
436
437 $record = new self($this->db);
438 $record->setVarsFromFetchObj($obj);
439
440 $records[$record->id] = $record;
441
442 $i++;
443 }
444 $this->db->free($resql);
445
446 return $records;
447 } else {
448 $this->errors[] = 'Error '.$this->db->lasterror();
449 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
450
451 return -1;
452 }
453 }
454
462 public function update(User $user, $notrigger = 0)
463 {
464 return $this->updateCommon($user, $notrigger);
465 }
466
474 public function delete(User $user, $notrigger = 0)
475 {
476 return $this->deleteCommon($user, $notrigger);
477 //return $this->deleteCommon($user, $notrigger, 1);
478 }
479
488 public function deleteLine(User $user, $idline, $notrigger = 0)
489 {
490 if ($this->status < 0) {
491 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
492 return -2;
493 }
494
495 return $this->deleteLineCommon($user, $idline, $notrigger);
496 }
497
498
506 public function validate($user, $notrigger = 0)
507 {
508 global $conf, $langs;
509
510 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
511
512 $error = 0;
513
514 // Protection
515 if ($this->status == self::STATUS_VALIDATED) {
516 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
517 return 0;
518 }
519
520 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->write))
521 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
522 {
523 $this->error='NotEnoughPermissions';
524 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
525 return -1;
526 }*/
527
528 $now = dol_now();
529
530 $this->db->begin();
531
532 // Define new ref
533 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
534 $num = $this->getNextNumRef();
535 } else {
536 $num = $this->ref;
537 }
538 $this->newref = $num;
539
540 if (!empty($num)) {
541 // Validate
542 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
543 $sql .= " SET ref = '".$this->db->escape($num)."',";
544 $sql .= " status = ".self::STATUS_VALIDATED;
545 if (!empty($this->fields['date_validation'])) {
546 $sql .= ", date_validation = '".$this->db->idate($now)."'";
547 }
548 if (!empty($this->fields['fk_user_valid'])) {
549 $sql .= ", fk_user_valid = ".((int) $user->id);
550 }
551 $sql .= " WHERE rowid = ".((int) $this->id);
552
553 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
554 $resql = $this->db->query($sql);
555 if (!$resql) {
556 dol_print_error($this->db);
557 $this->error = $this->db->lasterror();
558 $error++;
559 }
560
561 if (!$error && !$notrigger) {
562 // Call trigger
563 $result = $this->call_trigger('HRM_SKILLRANK_VALIDATE', $user);
564 if ($result < 0) {
565 $error++;
566 }
567 // End call triggers
568 }
569 }
570
571 if (!$error) {
572 $this->oldref = $this->ref;
573
574 // Rename directory if dir was a temporary ref
575 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
576 // Now we rename also files into index
577 $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)."'";
578 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
579 $resql = $this->db->query($sql);
580 if (!$resql) {
581 $error++;
582 $this->error = $this->db->lasterror();
583 }
584 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
585 $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
586 $resql = $this->db->query($sql);
587 if (!$resql) {
588 $error++;
589 $this->error = $this->db->lasterror();
590 }
591
592 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
593 $oldref = dol_sanitizeFileName($this->ref);
594 $newref = dol_sanitizeFileName($num);
595 $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
596 $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
597 if (!$error && file_exists($dirsource)) {
598 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
599
600 if (@rename($dirsource, $dirdest)) {
601 dol_syslog("Rename ok");
602 // Rename docs starting with $oldref with $newref
603 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
604 foreach ($listoffiles as $fileentry) {
605 $dirsource = $fileentry['name'];
606 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
607 $dirsource = $fileentry['path'].'/'.$dirsource;
608 $dirdest = $fileentry['path'].'/'.$dirdest;
609 @rename($dirsource, $dirdest);
610 }
611 }
612 }
613 }
614 }
615
616 // Set new ref and current status
617 if (!$error) {
618 $this->ref = $num;
619 $this->status = self::STATUS_VALIDATED;
620 }
621
622 if (!$error) {
623 $this->db->commit();
624 return 1;
625 } else {
626 $this->db->rollback();
627 return -1;
628 }
629 }
630
631
639 public function setDraft($user, $notrigger = 0)
640 {
641 // Protection
642 if ($this->status <= self::STATUS_DRAFT) {
643 return 0;
644 }
645
646 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
647 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
648 {
649 $this->error='Permission denied';
650 return -1;
651 }*/
652
653 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
654 }
655
663 public function cancel($user, $notrigger = 0)
664 {
665 // Protection
666 if ($this->status != self::STATUS_VALIDATED) {
667 return 0;
668 }
669
670 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
671 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
672 {
673 $this->error='Permission denied';
674 return -1;
675 }*/
676
677 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
678 }
679
687 public function reopen($user, $notrigger = 0)
688 {
689 // Protection
690 if ($this->status != self::STATUS_CANCELED) {
691 return 0;
692 }
693
694 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
695 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
696 {
697 $this->error='Permission denied';
698 return -1;
699 }*/
700
701 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
702 }
703
714 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
715 {
716 global $conf, $langs, $hookmanager;
717
718 if (!empty($conf->dol_no_mouse_hover)) {
719 $notooltip = 1; // Force disable tooltips
720 }
721
722 $result = '';
723
724 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
725 if (isset($this->status)) {
726 $label .= ' '.$this->getLibStatut(5);
727 }
728 $label .= '<br>';
729 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
730
731 $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
732
733 if ($option != 'nolink') {
734 // Add param to save lastsearch_values or not
735 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
736 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
737 $add_save_lastsearch_values = 1;
738 }
739 if ($add_save_lastsearch_values) {
740 $url .= '&save_lastsearch_values=1';
741 }
742 }
743
744 $linkclose = '';
745 if (empty($notooltip)) {
746 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
747 $label = $langs->trans("ShowSkillRank");
748 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
749 }
750 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
751 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
752 } else {
753 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
754 }
755
756 if ($option == 'nolink') {
757 $linkstart = '<span';
758 } else {
759 $linkstart = '<a href="'.$url.'"';
760 }
761 $linkstart .= $linkclose.'>';
762 if ($option == 'nolink') {
763 $linkend = '</span>';
764 } else {
765 $linkend = '</a>';
766 }
767
768 $result .= $linkstart;
769
770 if (empty($this->showphoto_on_popup)) {
771 if ($withpicto) {
772 $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);
773 }
774 } else {
775 if ($withpicto) {
776 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
777
778 list($class, $module) = explode('@', $this->picto);
779 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
780 $filearray = dol_dir_list($upload_dir, "files");
781 $filename = $filearray[0]['name'];
782 if (!empty($filename)) {
783 $pospoint = strpos($filearray[0]['name'], '.');
784
785 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
786 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
787 $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>';
788 } else {
789 $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>';
790 }
791
792 $result .= '</div>';
793 } else {
794 $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);
795 }
796 }
797 }
798
799 if ($withpicto != 2) {
800 $result .= $this->ref;
801 }
802
803 $result .= $linkend;
804 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
805
806 global $action, $hookmanager;
807 $hookmanager->initHooks(array('skillrankdao'));
808 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
809 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
810 if ($reshook > 0) {
811 $result = $hookmanager->resPrint;
812 } else {
813 $result .= $hookmanager->resPrint;
814 }
815
816 return $result;
817 }
818
825 public function getLibStatut($mode = 0)
826 {
827 return $this->LibStatut($this->status, $mode);
828 }
829
830 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
838 public function LibStatut($status, $mode = 0)
839 {
840 // phpcs:enable
841 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
842 global $langs;
843 //$langs->load("hrm");
844 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
845 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
846 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
847 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
848 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
849 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
850 }
851
852 $statusType = 'status'.$status;
853 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
854 if ($status == self::STATUS_CANCELED) {
855 $statusType = 'status6';
856 }
857
858 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
859 }
860
867 public function info($id)
868 {
869 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
870 $sql .= ' fk_user_creat, fk_user_modif';
871 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
872 $sql .= ' WHERE t.rowid = '.((int) $id);
873 $result = $this->db->query($sql);
874 if ($result) {
875 if ($this->db->num_rows($result)) {
876 $obj = $this->db->fetch_object($result);
877
878 $this->id = $obj->rowid;
879
880 $this->user_creation_id = $obj->fk_user_creat;
881 $this->user_modification_id = $obj->fk_user_modif;
882 $this->date_creation = $this->db->jdate($obj->datec);
883 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
884 }
885
886 $this->db->free($result);
887 } else {
888 dol_print_error($this->db);
889 }
890 }
891
898 public function initAsSpecimen()
899 {
900 // Set here init that are not commonf fields
901 // $this->property1 = ...
902 // $this->property2 = ...
903
904 return $this->initAsSpecimenCommon();
905 }
906
912 public function getLinesArray()
913 {
914 $this->lines = array();
915
916 /*
917 $objectline = new SkillRankLine($this->db);
918 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_skillrank:=:'.((int) $this->id).')');
919
920 if (is_numeric($result)) {
921 $this->error = $objectline->error;
922 $this->errors = $objectline->errors;
923 return $result;
924 } else {
925 $this->lines = $result;
926 return $this->lines;
927 }
928 */
929
930 return $this->lines;
931 }
932
938 public function getNextNumRef()
939 {
940 global $langs, $conf;
941 $langs->load("hrm");
942
943 if (!getDolGlobalString('hrm_SKILLRANK_ADDON')) {
944 $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
945 }
946
947 if (getDolGlobalString('hrm_SKILLRANK_ADDON')) {
948 $mybool = false;
949
950 $file = getDolGlobalString('hrm_SKILLRANK_ADDON') . ".php";
951 $classname = getDolGlobalString('hrm_SKILLRANK_ADDON');
952
953 // Include file with class
954 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
955 foreach ($dirmodels as $reldir) {
956 $dir = dol_buildpath($reldir."core/modules/hrm/");
957
958 // Load file with numbering class (if found)
959 $mybool = ((bool) @include_once $dir.$file) || $mybool;
960 }
961
962 if ($mybool === false) {
963 dol_print_error(null, "Failed to include file ".$file);
964 return '';
965 }
966
967 if (class_exists($classname)) {
968 $obj = new $classname();
969 $numref = $obj->getNextValue($this);
970
971 if ($numref != '' && $numref != '-1') {
972 return $numref;
973 } else {
974 $this->error = $obj->error;
975 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
976 return "";
977 }
978 } else {
979 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
980 return "";
981 }
982 } else {
983 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
984 return "";
985 }
986 }
987
999 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1000 {
1001 global $conf, $langs;
1002
1003 $result = 0;
1004 $includedocgeneration = 0;
1005
1006 $langs->load("hrm");
1007
1008 if (!dol_strlen($modele)) {
1009 $modele = 'standard_skillrank';
1010
1011 if (!empty($this->model_pdf)) {
1012 $modele = $this->model_pdf;
1013 } elseif (getDolGlobalString('SKILLRANK_ADDON_PDF')) {
1014 $modele = getDolGlobalString('SKILLRANK_ADDON_PDF');
1015 }
1016 }
1017
1018 $modelpath = "core/modules/hrm/doc/";
1019
1020 if ($includedocgeneration && !empty($modele)) {
1021 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1022 }
1023
1024 return $result;
1025 }
1026}
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:626
$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.