dolibarr 21.0.0-beta
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 );
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
143
144 // If this object has a subtable with lines
145
146 // /**
147 // * @var string Name of subtable line
148 // */
149 // public $table_element_line = 'hrm_skillrankline';
150
151 // /**
152 // * @var string Field with ID of parent key if this object has a parent
153 // */
154 // public $fk_element = 'fk_skillrank';
155
156 // /**
157 // * @var string Name of subtable class that manage subtable lines
158 // */
159 // public $class_element_line = 'SkillRankline';
160
161 // /**
162 // * @var array List of child tables. To test if we can delete object.
163 // */
164 // protected $childtables = array();
165
166 // /**
167 // * @var array List of child tables. To know object to delete on cascade.
168 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
169 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
170 // */
171 // protected $childtablesoncascade = array('hrm_skillrankdet');
172
173 // /**
174 // * @var SkillRankLine[] Array of subtable lines
175 // */
176 // public $lines = array();
177
178
179
185 public function __construct(DoliDB $db)
186 {
187 global $conf, $langs;
188
189 $this->db = $db;
190
191 $this->ismultientitymanaged = 0;
192 $this->isextrafieldmanaged = 0;
193
194 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
195 $this->fields['rowid']['visible'] = 0;
196 }
197 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
198 $this->fields['entity']['enabled'] = 0;
199 }
200
201 // Example to show how to set values of fields definition dynamically
202 /*if ($user->rights->hrm->skillrank->read) {
203 $this->fields['myfield']['visible'] = 1;
204 $this->fields['myfield']['noteditable'] = 0;
205 }*/
206
207 // Unset fields that are disabled
208 foreach ($this->fields as $key => $val) {
209 if (isset($val['enabled']) && empty($val['enabled'])) {
210 unset($this->fields[$key]);
211 }
212 }
213
214 // Translate some data of arrayofkeyval
215 if (is_object($langs)) {
216 foreach ($this->fields as $key => $val) {
217 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
218 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
219 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
220 }
221 }
222 }
223 }
224 }
225
233 public function create(User $user, $notrigger = 0)
234 {
235 global $langs;
236
237 $filter = '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")";
238
239 $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, $filter);
240 if (!empty($alreadyLinked)) {
241 $this->error = $langs->trans('ErrSkillAlreadyAdded');
242 return -1;
243 }
244
245 $resultcreate = $this->createCommon($user, $notrigger);
246
247 return $resultcreate;
248 }
249
258 public function createFromClone(User $user, $fromid, $fk_object = 0)
259 {
260 global $langs, $extrafields;
261 $error = 0;
262
263 dol_syslog(__METHOD__, LOG_DEBUG);
264
265 $object = new self($this->db);
266
267 $this->db->begin();
268
269 // Load source object
270 $result = $object->fetchCommon($fromid);
271 if ($result > 0 && !empty($object->table_element_line)) {
272 $object->fetchLines();
273 }
274
275 // get lines so they will be clone
276 //foreach($this->lines as $line)
277 // $line->fetch_optionals();
278
279 // Reset some properties
280 unset($object->id);
281 unset($object->fk_user_creat);
282 unset($object->import_key);
283 if (!empty($fk_object) && $fk_object > 0) {
284 unset($object->fk_object);
285 }
286
287
288 // Clear fields
289 if (property_exists($object, 'ref')) {
290 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
291 }
292 if (property_exists($object, 'label')) {
293 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
294 }
295 if (property_exists($object, 'status')) {
296 $object->status = self::STATUS_DRAFT;
297 }
298 if (property_exists($object, 'date_creation')) {
299 $object->date_creation = dol_now();
300 }
301 if (property_exists($object, 'date_modification')) {
302 $object->date_modification = null;
303 }
304 if (!empty($fk_object) && $fk_object > 0) {
305 if (property_exists($object, 'fk_object')) {
306 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
307 }
308 }
309 // ...
310 // Clear extrafields that are unique
311 if (is_array($object->array_options) && count($object->array_options) > 0) {
312 $extrafields->fetch_name_optionals_label($this->table_element);
313 foreach ($object->array_options as $key => $option) {
314 $shortkey = preg_replace('/options_/', '', $key);
315 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
316 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
317 unset($object->array_options[$key]);
318 }
319 }
320 }
321
322 // Create clone
323 $object->context['createfromclone'] = 'createfromclone';
324 $result = $object->createCommon($user);
325 if ($result < 0) {
326 $error++;
328 }
329
330 if (!$error) {
331 // copy internal contacts
332 if ($this->copy_linked_contact($object, 'internal') < 0) {
333 $error++;
334 }
335 }
336
337 if (!$error) {
338 // copy external contacts if same company
339 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
340 if ($this->copy_linked_contact($object, 'external') < 0) {
341 $error++;
342 }
343 }
344 }
345
346 unset($object->context['createfromclone']);
347
348 // End
349 if (!$error) {
350 $this->db->commit();
351 return $object;
352 } else {
353 $this->db->rollback();
354 return -1;
355 }
356 }
357
365 public function fetch($id, $ref = null)
366 {
367 $result = $this->fetchCommon($id, $ref);
368 if ($result > 0 && !empty($this->table_element_line)) {
369 $this->fetchLines();
370 }
371 return $result;
372 }
373
379 public function fetchLines()
380 {
381 $this->lines = array();
382
383 $result = $this->fetchLinesCommon();
384 return $result;
385 }
386
395 public function cloneFromCurrentSkill($currentSkill, $fk_user)
396 {
397 global $user;
398
399 $this->fk_skill = $currentSkill->fk_skill;
400 $this->rankorder = $currentSkill->rankorder;
401 $this->fk_object = $fk_user;
402 $this->date_creation = dol_now();
403 $this->fk_user_creat = $user->id;
404 $this->fk_user_modif = $user->id;
405 $this->objecttype = self::SKILLRANK_TYPE_USER;
406 $result = $this->create($user);
407
408 return $result;
409 }
410
423 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
424 {
425 dol_syslog(__METHOD__, LOG_DEBUG);
426
427 $records = array();
428
429 $sql = 'SELECT ';
430 $sql .= $this->getFieldList('t');
431 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
432 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
433 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
434 } else {
435 $sql .= ' WHERE 1 = 1';
436 }
437
438 // Manage filter
439 $errormessage = '';
440 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
441 if ($errormessage) {
442 $this->errors[] = $errormessage;
443 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
444 return -1;
445 }
446
447 if (!empty($sortfield)) {
448 $sql .= $this->db->order($sortfield, $sortorder);
449 }
450 if (!empty($limit)) {
451 $sql .= ' '.$this->db->plimit($limit, $offset);
452 }
453
454 $resql = $this->db->query($sql);
455 if ($resql) {
456 $num = $this->db->num_rows($resql);
457 $i = 0;
458 while ($i < ($limit ? min($limit, $num) : $num)) {
459 $obj = $this->db->fetch_object($resql);
460
461 $record = new self($this->db);
462 $record->setVarsFromFetchObj($obj);
463
464 $records[$record->id] = $record;
465
466 $i++;
467 }
468 $this->db->free($resql);
469
470 return $records;
471 } else {
472 $this->errors[] = 'Error '.$this->db->lasterror();
473 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
474
475 return -1;
476 }
477 }
478
486 public function update(User $user, $notrigger = 0)
487 {
488 return $this->updateCommon($user, $notrigger);
489 }
490
498 public function delete(User $user, $notrigger = 0)
499 {
500 return $this->deleteCommon($user, $notrigger);
501 //return $this->deleteCommon($user, $notrigger, 1);
502 }
503
512 public function deleteLine(User $user, $idline, $notrigger = 0)
513 {
514 if ($this->status < 0) {
515 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
516 return -2;
517 }
518
519 return $this->deleteLineCommon($user, $idline, $notrigger);
520 }
521
522
530 public function validate($user, $notrigger = 0)
531 {
532 global $conf, $langs;
533
534 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
535
536 $error = 0;
537
538 // Protection
539 if ($this->status == self::STATUS_VALIDATED) {
540 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
541 return 0;
542 }
543
544 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->write))
545 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
546 {
547 $this->error='NotEnoughPermissions';
548 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
549 return -1;
550 }*/
551
552 $now = dol_now();
553
554 $this->db->begin();
555
556 // Define new ref
557 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
558 $num = $this->getNextNumRef();
559 } else {
560 $num = $this->ref;
561 }
562 $this->newref = $num;
563
564 if (!empty($num)) {
565 // Validate
566 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
567 $sql .= " SET ref = '".$this->db->escape($num)."',";
568 $sql .= " status = ".self::STATUS_VALIDATED;
569 if (!empty($this->fields['date_validation'])) {
570 $sql .= ", date_validation = '".$this->db->idate($now)."'";
571 }
572 if (!empty($this->fields['fk_user_valid'])) {
573 $sql .= ", fk_user_valid = ".((int) $user->id);
574 }
575 $sql .= " WHERE rowid = ".((int) $this->id);
576
577 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
578 $resql = $this->db->query($sql);
579 if (!$resql) {
580 dol_print_error($this->db);
581 $this->error = $this->db->lasterror();
582 $error++;
583 }
584
585 if (!$error && !$notrigger) {
586 // Call trigger
587 $result = $this->call_trigger('HRM_SKILLRANK_VALIDATE', $user);
588 if ($result < 0) {
589 $error++;
590 }
591 // End call triggers
592 }
593 }
594
595 if (!$error) {
596 $this->oldref = $this->ref;
597
598 // Rename directory if dir was a temporary ref
599 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
600 // Now we rename also files into index
601 $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)."'";
602 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
603 $resql = $this->db->query($sql);
604 if (!$resql) {
605 $error++;
606 $this->error = $this->db->lasterror();
607 }
608 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
609 $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
610 $resql = $this->db->query($sql);
611 if (!$resql) {
612 $error++;
613 $this->error = $this->db->lasterror();
614 }
615
616 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
617 $oldref = dol_sanitizeFileName($this->ref);
618 $newref = dol_sanitizeFileName($num);
619 $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
620 $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
621 if (!$error && file_exists($dirsource)) {
622 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
623
624 if (@rename($dirsource, $dirdest)) {
625 dol_syslog("Rename ok");
626 // Rename docs starting with $oldref with $newref
627 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
628 foreach ($listoffiles as $fileentry) {
629 $dirsource = $fileentry['name'];
630 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
631 $dirsource = $fileentry['path'].'/'.$dirsource;
632 $dirdest = $fileentry['path'].'/'.$dirdest;
633 @rename($dirsource, $dirdest);
634 }
635 }
636 }
637 }
638 }
639
640 // Set new ref and current status
641 if (!$error) {
642 $this->ref = $num;
643 $this->status = self::STATUS_VALIDATED;
644 }
645
646 if (!$error) {
647 $this->db->commit();
648 return 1;
649 } else {
650 $this->db->rollback();
651 return -1;
652 }
653 }
654
655
663 public function setDraft($user, $notrigger = 0)
664 {
665 // Protection
666 if ($this->status <= self::STATUS_DRAFT) {
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_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
678 }
679
687 public function cancel($user, $notrigger = 0)
688 {
689 // Protection
690 if ($this->status != self::STATUS_VALIDATED) {
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_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
702 }
703
711 public function reopen($user, $notrigger = 0)
712 {
713 // Protection
714 if ($this->status != self::STATUS_CANCELED) {
715 return 0;
716 }
717
718 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
719 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
720 {
721 $this->error='Permission denied';
722 return -1;
723 }*/
724
725 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
726 }
727
738 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
739 {
740 global $conf, $langs, $hookmanager;
741
742 if (!empty($conf->dol_no_mouse_hover)) {
743 $notooltip = 1; // Force disable tooltips
744 }
745
746 $result = '';
747
748 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
749 if (isset($this->status)) {
750 $label .= ' '.$this->getLibStatut(5);
751 }
752 $label .= '<br>';
753 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
754
755 $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
756
757 if ($option != 'nolink') {
758 // Add param to save lastsearch_values or not
759 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
760 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
761 $add_save_lastsearch_values = 1;
762 }
763 if ($add_save_lastsearch_values) {
764 $url .= '&save_lastsearch_values=1';
765 }
766 }
767
768 $linkclose = '';
769 if (empty($notooltip)) {
770 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
771 $label = $langs->trans("ShowSkillRank");
772 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
773 }
774 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
775 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
776 } else {
777 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
778 }
779
780 if ($option == 'nolink') {
781 $linkstart = '<span';
782 } else {
783 $linkstart = '<a href="'.$url.'"';
784 }
785 $linkstart .= $linkclose.'>';
786 if ($option == 'nolink') {
787 $linkend = '</span>';
788 } else {
789 $linkend = '</a>';
790 }
791
792 $result .= $linkstart;
793
794 if (empty($this->showphoto_on_popup)) {
795 if ($withpicto) {
796 $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);
797 }
798 } else {
799 if ($withpicto) {
800 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
801
802 list($class, $module) = explode('@', $this->picto);
803 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
804 $filearray = dol_dir_list($upload_dir, "files");
805 $filename = $filearray[0]['name'];
806 if (!empty($filename)) {
807 $pospoint = strpos($filearray[0]['name'], '.');
808
809 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
810 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
811 $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>';
812 } else {
813 $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>';
814 }
815
816 $result .= '</div>';
817 } else {
818 $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);
819 }
820 }
821 }
822
823 if ($withpicto != 2) {
824 $result .= $this->ref;
825 }
826
827 $result .= $linkend;
828 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
829
830 global $action, $hookmanager;
831 $hookmanager->initHooks(array('skillrankdao'));
832 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
833 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
834 if ($reshook > 0) {
835 $result = $hookmanager->resPrint;
836 } else {
837 $result .= $hookmanager->resPrint;
838 }
839
840 return $result;
841 }
842
849 public function getLibStatut($mode = 0)
850 {
851 return $this->LibStatut($this->status, $mode);
852 }
853
854 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
862 public function LibStatut($status, $mode = 0)
863 {
864 // phpcs:enable
865 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
866 global $langs;
867 //$langs->load("hrm");
868 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
869 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
870 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
871 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
872 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
873 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
874 }
875
876 $statusType = 'status'.$status;
877 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
878 if ($status == self::STATUS_CANCELED) {
879 $statusType = 'status6';
880 }
881
882 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
883 }
884
891 public function info($id)
892 {
893 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
894 $sql .= ' fk_user_creat, fk_user_modif';
895 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
896 $sql .= ' WHERE t.rowid = '.((int) $id);
897 $result = $this->db->query($sql);
898 if ($result) {
899 if ($this->db->num_rows($result)) {
900 $obj = $this->db->fetch_object($result);
901
902 $this->id = $obj->rowid;
903
904 $this->user_creation_id = $obj->fk_user_creat;
905 $this->user_modification_id = $obj->fk_user_modif;
906 $this->date_creation = $this->db->jdate($obj->datec);
907 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
908 }
909
910 $this->db->free($result);
911 } else {
912 dol_print_error($this->db);
913 }
914 }
915
922 public function initAsSpecimen()
923 {
924 // Set here init that are not commonf fields
925 // $this->property1 = ...
926 // $this->property2 = ...
927
928 return $this->initAsSpecimenCommon();
929 }
930
936 public function getLinesArray()
937 {
938 $this->lines = array();
939
940 /*
941 $objectline = new SkillRankLine($this->db);
942 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_skillrank:=:'.((int) $this->id).')');
943
944 if (is_numeric($result)) {
945 $this->error = $objectline->error;
946 $this->errors = $objectline->errors;
947 return $result;
948 } else {
949 $this->lines = $result;
950 return $this->lines;
951 }
952 */
953
954 return $this->lines;
955 }
956
962 public function getNextNumRef()
963 {
964 global $langs, $conf;
965 $langs->load("hrm");
966
967 if (!getDolGlobalString('hrm_SKILLRANK_ADDON')) {
968 $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
969 }
970
971 if (getDolGlobalString('hrm_SKILLRANK_ADDON')) {
972 $mybool = false;
973
974 $file = getDolGlobalString('hrm_SKILLRANK_ADDON') . ".php";
975 $classname = getDolGlobalString('hrm_SKILLRANK_ADDON');
976
977 // Include file with class
978 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
979 foreach ($dirmodels as $reldir) {
980 $dir = dol_buildpath($reldir."core/modules/hrm/");
981
982 // Load file with numbering class (if found)
983 $mybool = ((bool) @include_once $dir.$file) || $mybool;
984 }
985
986 if (!$mybool) {
987 dol_print_error(null, "Failed to include file ".$file);
988 return '';
989 }
990
991 if (class_exists($classname)) {
992 $obj = new $classname();
993 '@phan-var-force ModeleNumRefEvaluation $obj';
994 $numref = $obj->getNextValue($this);
995
996 if ($numref != '' && $numref != '-1') {
997 return $numref;
998 } else {
999 $this->error = $obj->error;
1000 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1001 return "";
1002 }
1003 } else {
1004 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1005 return "";
1006 }
1007 } else {
1008 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1009 return "";
1010 }
1011 }
1012
1024 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1025 {
1026 global $conf, $langs;
1027
1028 $result = 0;
1029 $includedocgeneration = 0;
1030
1031 $langs->load("hrm");
1032
1033 if (!dol_strlen($modele)) {
1034 $modele = 'standard_skillrank';
1035
1036 if (!empty($this->model_pdf)) {
1037 $modele = $this->model_pdf;
1038 } elseif (getDolGlobalString('SKILLRANK_ADDON_PDF')) {
1039 $modele = getDolGlobalString('SKILLRANK_ADDON_PDF');
1040 }
1041 }
1042
1043 $modelpath = "core/modules/hrm/doc/";
1044
1045 if ($includedocgeneration && !empty($modele)) {
1046 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1047 }
1048
1049 return $result;
1050 }
1051}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
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.
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: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.
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_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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79