dolibarr 19.0.3
skillrank.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5 * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6 * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skillrank.lib.php';
31
36{
40 public $module = 'hrm';
41
45 public $element = 'skillrank';
46
50 public $table_element = 'hrm_skillrank';
51
56 public $ismultientitymanaged = 0;
57
61 public $isextrafieldmanaged = 0;
62
66 public $picto = 'skillrank@hrm';
67
68
69 const STATUS_DRAFT = 0;
70 const STATUS_VALIDATED = 1;
71 const STATUS_CANCELED = 9;
72
73 const SKILLRANK_TYPE_JOB = "job";
74 const SKILLRANK_TYPE_USER = "user";
75 const SKILLRANK_TYPE_EVALDET = "evaluationdet";
76
103 // BEGIN MODULEBUILDER PROPERTIES
107 public $fields=array(
108 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
109 'fk_skill' => array('type'=>'integer:Skill:hrm/class/skill.class.php:1', 'label'=>'Skill', 'enabled'=>'1', 'position'=>3, 'notnull'=>1, 'visible'=>1, 'index'=>1,),
110 'rankorder' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>'1', 'position'=>4, 'notnull'=>1, 'visible'=>1, 'default' => 0),
111 'fk_object' => array('type'=>'integer', 'label'=>'object', 'enabled'=>'1', 'position'=>5, 'notnull'=>1, 'visible'=>0,),
112 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
113 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
114 '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',),
115 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
116 'objecttype' => array('type'=>'varchar(128)', 'label'=>'objecttype', 'enabled'=>'1', 'position'=>6, 'notnull'=>1, 'visible'=>0,),
117 );
118 public $rowid;
119 public $fk_skill;
120 public $rank;
121 public $fk_object;
122 public $date_creation;
123 public $tms;
124 public $fk_user_creat;
125 public $fk_user_modif;
126 public $objecttype;
127 // END MODULEBUILDER PROPERTIES
128 public $rankorder;
129
130
131 // If this object has a subtable with lines
132
133 // /**
134 // * @var string Name of subtable line
135 // */
136 // public $table_element_line = 'hrm_skillrankline';
137
138 // /**
139 // * @var string Field with ID of parent key if this object has a parent
140 // */
141 // public $fk_element = 'fk_skillrank';
142
143 // /**
144 // * @var string Name of subtable class that manage subtable lines
145 // */
146 // public $class_element_line = 'SkillRankline';
147
148 // /**
149 // * @var array List of child tables. To test if we can delete object.
150 // */
151 // protected $childtables = array();
152
153 // /**
154 // * @var array List of child tables. To know object to delete on cascade.
155 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
156 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
157 // */
158 // protected $childtablesoncascade = array('hrm_skillrankdet');
159
160 // /**
161 // * @var SkillRankLine[] Array of subtable lines
162 // */
163 // public $lines = array();
164
165
166
172 public function __construct(DoliDB $db)
173 {
174 global $conf, $langs;
175
176 $this->db = $db;
177
178 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
179 $this->fields['rowid']['visible'] = 0;
180 }
181 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
182 $this->fields['entity']['enabled'] = 0;
183 }
184
185 // Example to show how to set values of fields definition dynamically
186 /*if ($user->rights->hrm->skillrank->read) {
187 $this->fields['myfield']['visible'] = 1;
188 $this->fields['myfield']['noteditable'] = 0;
189 }*/
190
191 // Unset fields that are disabled
192 foreach ($this->fields as $key => $val) {
193 if (isset($val['enabled']) && empty($val['enabled'])) {
194 unset($this->fields[$key]);
195 }
196 }
197
198 // Translate some data of arrayofkeyval
199 if (is_object($langs)) {
200 foreach ($this->fields as $key => $val) {
201 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
202 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
203 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
204 }
205 }
206 }
207 }
208 }
209
217 public function create(User $user, $notrigger = false)
218 {
219 global $langs;
220
221 $sqlfilter = 'fk_object='.((int) $this->fk_object)." AND objecttype='".$this->db->escape($this->objecttype)."' AND fk_skill = ".((int) $this->fk_skill);
222 $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, array('customsql' => $sqlfilter));
223 if (!empty($alreadyLinked)) {
224 $this->error = $langs->trans('ErrSkillAlreadyAdded');
225 return -1;
226 }
227
228 $resultcreate = $this->createCommon($user, $notrigger);
229
230 return $resultcreate;
231 }
232
241 public function createFromClone(User $user, $fromid, $fk_object = 0)
242 {
243 global $langs, $extrafields;
244 $error = 0;
245
246 dol_syslog(__METHOD__, LOG_DEBUG);
247
248 $object = new self($this->db);
249
250 $this->db->begin();
251
252 // Load source object
253 $result = $object->fetchCommon($fromid);
254 if ($result > 0 && !empty($object->table_element_line)) {
255 $object->fetchLines();
256 }
257
258 // get lines so they will be clone
259 //foreach($this->lines as $line)
260 // $line->fetch_optionals();
261
262 // Reset some properties
263 unset($object->id);
264 unset($object->fk_user_creat);
265 unset($object->import_key);
266 if (!empty($fk_object) && $fk_object > 0) {
267 unset($object->fk_object);
268 }
269
270
271 // Clear fields
272 if (property_exists($object, 'ref')) {
273 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
274 }
275 if (property_exists($object, 'label')) {
276 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
277 }
278 if (property_exists($object, 'status')) {
279 $object->status = self::STATUS_DRAFT;
280 }
281 if (property_exists($object, 'date_creation')) {
282 $object->date_creation = dol_now();
283 }
284 if (property_exists($object, 'date_modification')) {
285 $object->date_modification = null;
286 }
287 if (!empty($fk_object) && $fk_object > 0) {
288 if (property_exists($object, 'fk_object')) {
289 $object->fk_object = ($fk_object = 0 ? $this->fk_object : $fk_object);
290 }
291 }
292 // ...
293 // Clear extrafields that are unique
294 if (is_array($object->array_options) && count($object->array_options) > 0) {
295 $extrafields->fetch_name_optionals_label($this->table_element);
296 foreach ($object->array_options as $key => $option) {
297 $shortkey = preg_replace('/options_/', '', $key);
298 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
299 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
300 unset($object->array_options[$key]);
301 }
302 }
303 }
304
305 // Create clone
306 $object->context['createfromclone'] = 'createfromclone';
307 $result = $object->createCommon($user);
308 if ($result < 0) {
309 $error++;
310 $this->error = $object->error;
311 $this->errors = $object->errors;
312 }
313
314 if (!$error) {
315 // copy internal contacts
316 if ($this->copy_linked_contact($object, 'internal') < 0) {
317 $error++;
318 }
319 }
320
321 if (!$error) {
322 // copy external contacts if same company
323 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
324 if ($this->copy_linked_contact($object, 'external') < 0) {
325 $error++;
326 }
327 }
328 }
329
330 unset($object->context['createfromclone']);
331
332 // End
333 if (!$error) {
334 $this->db->commit();
335 return $object;
336 } else {
337 $this->db->rollback();
338 return -1;
339 }
340 }
341
349 public function fetch($id, $ref = null)
350 {
351 $result = $this->fetchCommon($id, $ref);
352 if ($result > 0 && !empty($this->table_element_line)) {
353 $this->fetchLines();
354 }
355 return $result;
356 }
357
363 public function fetchLines()
364 {
365 $this->lines = array();
366
367 $result = $this->fetchLinesCommon();
368 return $result;
369 }
370
379 public function cloneFromCurrentSkill($currentSkill, $fk_user)
380 {
381 global $user;
382
383 $this->fk_skill = $currentSkill->fk_skill;
384 $this->rankorder = $currentSkill->rankorder;
385 $this->fk_object = $fk_user;
386 $this->date_creation = dol_now();
387 $this->fk_user_creat = $user->id;
388 $this->fk_user_modif = $user->id;
389 $this->objecttype = self::SKILLRANK_TYPE_USER;
390 $result = $this->create($user);
391
392 return $result;
393 }
394
406 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
407 {
408 global $conf;
409
410 dol_syslog(__METHOD__, LOG_DEBUG);
411
412 $records = array();
413
414 $sql = 'SELECT ';
415 $sql .= $this->getFieldList('t');
416 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
417 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
418 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
419 } else {
420 $sql .= ' WHERE 1 = 1';
421 }
422 // Manage filter
423 $sqlwhere = array();
424 if (count($filter) > 0) {
425 foreach ($filter as $key => $value) {
426 if ($key == 't.rowid') {
427 $sqlwhere[] = $key." = ".((int) $value);
428 } elseif (array_key_exists($key, $this->fields) && $key != 'customsql' && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
429 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
430 } elseif ($key == 'customsql') {
431 $sqlwhere[] = $value;
432 } elseif (strpos($value, '%') === false) {
433 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
434 } else {
435 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
436 }
437 }
438 }
439 if (count($sqlwhere) > 0) {
440 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
441 }
442
443 if (!empty($sortfield)) {
444 $sql .= $this->db->order($sortfield, $sortorder);
445 }
446 if (!empty($limit)) {
447 $sql .= ' '.$this->db->plimit($limit, $offset);
448 }
449
450 $resql = $this->db->query($sql);
451 if ($resql) {
452 $num = $this->db->num_rows($resql);
453 $i = 0;
454 while ($i < ($limit ? min($limit, $num) : $num)) {
455 $obj = $this->db->fetch_object($resql);
456
457 $record = new self($this->db);
458 $record->setVarsFromFetchObj($obj);
459
460 $records[$record->id] = $record;
461
462 $i++;
463 }
464 $this->db->free($resql);
465
466 return $records;
467 } else {
468 $this->errors[] = 'Error '.$this->db->lasterror();
469 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
470
471 return -1;
472 }
473 }
474
482 public function update(User $user, $notrigger = false)
483 {
484 return $this->updateCommon($user, $notrigger);
485 }
486
494 public function delete(User $user, $notrigger = false)
495 {
496 return $this->deleteCommon($user, $notrigger);
497 //return $this->deleteCommon($user, $notrigger, 1);
498 }
499
508 public function deleteLine(User $user, $idline, $notrigger = false)
509 {
510 if ($this->status < 0) {
511 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
512 return -2;
513 }
514
515 return $this->deleteLineCommon($user, $idline, $notrigger);
516 }
517
518
526 public function validate($user, $notrigger = 0)
527 {
528 global $conf, $langs;
529
530 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
531
532 $error = 0;
533
534 // Protection
535 if ($this->status == self::STATUS_VALIDATED) {
536 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
537 return 0;
538 }
539
540 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->write))
541 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
542 {
543 $this->error='NotEnoughPermissions';
544 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
545 return -1;
546 }*/
547
548 $now = dol_now();
549
550 $this->db->begin();
551
552 // Define new ref
553 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
554 $num = $this->getNextNumRef();
555 } else {
556 $num = $this->ref;
557 }
558 $this->newref = $num;
559
560 if (!empty($num)) {
561 // Validate
562 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
563 $sql .= " SET ref = '".$this->db->escape($num)."',";
564 $sql .= " status = ".self::STATUS_VALIDATED;
565 if (!empty($this->fields['date_validation'])) {
566 $sql .= ", date_validation = '".$this->db->idate($now)."'";
567 }
568 if (!empty($this->fields['fk_user_valid'])) {
569 $sql .= ", fk_user_valid = ".((int) $user->id);
570 }
571 $sql .= " WHERE rowid = ".((int) $this->id);
572
573 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
574 $resql = $this->db->query($sql);
575 if (!$resql) {
576 dol_print_error($this->db);
577 $this->error = $this->db->lasterror();
578 $error++;
579 }
580
581 if (!$error && !$notrigger) {
582 // Call trigger
583 $result = $this->call_trigger('HRM_SKILLRANK_VALIDATE', $user);
584 if ($result < 0) {
585 $error++;
586 }
587 // End call triggers
588 }
589 }
590
591 if (!$error) {
592 $this->oldref = $this->ref;
593
594 // Rename directory if dir was a temporary ref
595 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
596 // Now we rename also files into index
597 $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)."'";
598 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
599 $resql = $this->db->query($sql);
600 if (!$resql) {
601 $error++;
602 $this->error = $this->db->lasterror();
603 }
604 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
605 $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
606 $resql = $this->db->query($sql);
607 if (!$resql) {
608 $error++;
609 $this->error = $this->db->lasterror();
610 }
611
612 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
613 $oldref = dol_sanitizeFileName($this->ref);
614 $newref = dol_sanitizeFileName($num);
615 $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
616 $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
617 if (!$error && file_exists($dirsource)) {
618 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
619
620 if (@rename($dirsource, $dirdest)) {
621 dol_syslog("Rename ok");
622 // Rename docs starting with $oldref with $newref
623 $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
624 foreach ($listoffiles as $fileentry) {
625 $dirsource = $fileentry['name'];
626 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
627 $dirsource = $fileentry['path'].'/'.$dirsource;
628 $dirdest = $fileentry['path'].'/'.$dirdest;
629 @rename($dirsource, $dirdest);
630 }
631 }
632 }
633 }
634 }
635
636 // Set new ref and current status
637 if (!$error) {
638 $this->ref = $num;
639 $this->status = self::STATUS_VALIDATED;
640 }
641
642 if (!$error) {
643 $this->db->commit();
644 return 1;
645 } else {
646 $this->db->rollback();
647 return -1;
648 }
649 }
650
651
659 public function setDraft($user, $notrigger = 0)
660 {
661 // Protection
662 if ($this->status <= self::STATUS_DRAFT) {
663 return 0;
664 }
665
666 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
667 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
668 {
669 $this->error='Permission denied';
670 return -1;
671 }*/
672
673 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
674 }
675
683 public function cancel($user, $notrigger = 0)
684 {
685 // Protection
686 if ($this->status != self::STATUS_VALIDATED) {
687 return 0;
688 }
689
690 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
691 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
692 {
693 $this->error='Permission denied';
694 return -1;
695 }*/
696
697 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
698 }
699
707 public function reopen($user, $notrigger = 0)
708 {
709 // Protection
710 if ($this->status != self::STATUS_CANCELED) {
711 return 0;
712 }
713
714 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
715 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
716 {
717 $this->error='Permission denied';
718 return -1;
719 }*/
720
721 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
722 }
723
734 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
735 {
736 global $conf, $langs, $hookmanager;
737
738 if (!empty($conf->dol_no_mouse_hover)) {
739 $notooltip = 1; // Force disable tooltips
740 }
741
742 $result = '';
743
744 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
745 if (isset($this->status)) {
746 $label .= ' '.$this->getLibStatut(5);
747 }
748 $label .= '<br>';
749 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
750
751 $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
752
753 if ($option != 'nolink') {
754 // Add param to save lastsearch_values or not
755 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
756 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
757 $add_save_lastsearch_values = 1;
758 }
759 if ($add_save_lastsearch_values) {
760 $url .= '&save_lastsearch_values=1';
761 }
762 }
763
764 $linkclose = '';
765 if (empty($notooltip)) {
766 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
767 $label = $langs->trans("ShowSkillRank");
768 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
769 }
770 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
771 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
772 } else {
773 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
774 }
775
776 if ($option == 'nolink') {
777 $linkstart = '<span';
778 } else {
779 $linkstart = '<a href="'.$url.'"';
780 }
781 $linkstart .= $linkclose.'>';
782 if ($option == 'nolink') {
783 $linkend = '</span>';
784 } else {
785 $linkend = '</a>';
786 }
787
788 $result .= $linkstart;
789
790 if (empty($this->showphoto_on_popup)) {
791 if ($withpicto) {
792 $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);
793 }
794 } else {
795 if ($withpicto) {
796 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
797
798 list($class, $module) = explode('@', $this->picto);
799 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
800 $filearray = dol_dir_list($upload_dir, "files");
801 $filename = $filearray[0]['name'];
802 if (!empty($filename)) {
803 $pospoint = strpos($filearray[0]['name'], '.');
804
805 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
806 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
807 $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>';
808 } else {
809 $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>';
810 }
811
812 $result .= '</div>';
813 } else {
814 $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);
815 }
816 }
817 }
818
819 if ($withpicto != 2) {
820 $result .= $this->ref;
821 }
822
823 $result .= $linkend;
824 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
825
826 global $action, $hookmanager;
827 $hookmanager->initHooks(array('skillrankdao'));
828 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
829 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
830 if ($reshook > 0) {
831 $result = $hookmanager->resPrint;
832 } else {
833 $result .= $hookmanager->resPrint;
834 }
835
836 return $result;
837 }
838
845 public function getLibStatut($mode = 0)
846 {
847 return $this->LibStatut($this->status, $mode);
848 }
849
850 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
858 public function LibStatut($status, $mode = 0)
859 {
860 // phpcs:enable
861 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
862 global $langs;
863 //$langs->load("hrm");
864 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
865 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
866 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
867 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
868 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
869 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
870 }
871
872 $statusType = 'status'.$status;
873 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
874 if ($status == self::STATUS_CANCELED) {
875 $statusType = 'status6';
876 }
877
878 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
879 }
880
887 public function info($id)
888 {
889 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
890 $sql .= ' fk_user_creat, fk_user_modif';
891 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
892 $sql .= ' WHERE t.rowid = '.((int) $id);
893 $result = $this->db->query($sql);
894 if ($result) {
895 if ($this->db->num_rows($result)) {
896 $obj = $this->db->fetch_object($result);
897
898 $this->id = $obj->rowid;
899
900 $this->user_creation_id = $obj->fk_user_creat;
901 $this->user_modification_id = $obj->fk_user_modif;
902 $this->date_creation = $this->db->jdate($obj->datec);
903 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
904 }
905
906 $this->db->free($result);
907 } else {
908 dol_print_error($this->db);
909 }
910 }
911
918 public function initAsSpecimen()
919 {
920 // Set here init that are not commonf fields
921 // $this->property1 = ...
922 // $this->property2 = ...
923
924 $this->initAsSpecimenCommon();
925 }
926
932 public function getLinesArray()
933 {
934 $this->lines = array();
935
936 /*
937 $objectline = new SkillRankLine($this->db);
938 $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_skillrank = '.((int) $this->id)));
939
940 if (is_numeric($result)) {
941 $this->error = $objectline->error;
942 $this->errors = $objectline->errors;
943 return $result;
944 } else {
945 $this->lines = $result;
946 return $this->lines;
947 }
948 */
949
950 return $this->lines;
951 }
952
958 public function getNextNumRef()
959 {
960 global $langs, $conf;
961 $langs->load("hrm");
962
963 if (!getDolGlobalString('hrm_SKILLRANK_ADDON')) {
964 $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
965 }
966
967 if (getDolGlobalString('hrm_SKILLRANK_ADDON')) {
968 $mybool = false;
969
970 $file = getDolGlobalString('hrm_SKILLRANK_ADDON') . ".php";
971 $classname = $conf->global->hrm_SKILLRANK_ADDON;
972
973 // Include file with class
974 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
975 foreach ($dirmodels as $reldir) {
976 $dir = dol_buildpath($reldir."core/modules/hrm/");
977
978 // Load file with numbering class (if found)
979 $mybool |= @include_once $dir.$file;
980 }
981
982 if ($mybool === false) {
983 dol_print_error('', "Failed to include file ".$file);
984 return '';
985 }
986
987 if (class_exists($classname)) {
988 $obj = new $classname();
989 $numref = $obj->getNextValue($this);
990
991 if ($numref != '' && $numref != '-1') {
992 return $numref;
993 } else {
994 $this->error = $obj->error;
995 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
996 return "";
997 }
998 } else {
999 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1000 return "";
1001 }
1002 } else {
1003 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1004 return "";
1005 }
1006 }
1007
1019 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1020 {
1021 global $conf, $langs;
1022
1023 $result = 0;
1024 $includedocgeneration = 0;
1025
1026 $langs->load("hrm");
1027
1028 if (!dol_strlen($modele)) {
1029 $modele = 'standard_skillrank';
1030
1031 if (!empty($this->model_pdf)) {
1032 $modele = $this->model_pdf;
1033 } elseif (getDolGlobalString('SKILLRANK_ADDON_PDF')) {
1034 $modele = $conf->global->SKILLRANK_ADDON_PDF;
1035 }
1036 }
1037
1038 $modelpath = "core/modules/hrm/doc/";
1039
1040 if ($includedocgeneration && !empty($modele)) {
1041 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1042 }
1043
1044 return $result;
1045 }
1046
1054 public function doScheduledJob()
1055 {
1056 global $conf, $langs;
1057
1058 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1059
1060 $error = 0;
1061 $this->output = '';
1062 $this->error = '';
1063
1064 dol_syslog(__METHOD__, LOG_DEBUG);
1065
1066 $now = dol_now();
1067
1068 $this->db->begin();
1069
1070 // ...
1071
1072 $this->db->commit();
1073
1074 return $error;
1075 }
1076
1087 // public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
1088 // {
1089 // if ($key == "rank") {
1090 // return displayRankInfos($this);
1091 // } else return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
1092 // }
1093}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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=false)
Delete a line of object in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
LibStatut($status, $mode=0)
Return the status.
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 optionaly 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.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
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.
update(User $user, $notrigger=false)
Update object into database.
getLinesArray()
Create an array of lines.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.