dolibarr  16.0.5
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
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skillrank.lib.php';
31 
35 class SkillRank extends CommonObject
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 
129 
130  // If this object has a subtable with lines
131 
132  // /**
133  // * @var string Name of subtable line
134  // */
135  // public $table_element_line = 'hrm_skillrankline';
136 
137  // /**
138  // * @var string Field with ID of parent key if this object has a parent
139  // */
140  // public $fk_element = 'fk_skillrank';
141 
142  // /**
143  // * @var string Name of subtable class that manage subtable lines
144  // */
145  // public $class_element_line = 'SkillRankline';
146 
147  // /**
148  // * @var array List of child tables. To test if we can delete object.
149  // */
150  // protected $childtables = array();
151 
152  // /**
153  // * @var array List of child tables. To know object to delete on cascade.
154  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
155  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
156  // */
157  // protected $childtablesoncascade = array('hrm_skillrankdet');
158 
159  // /**
160  // * @var SkillRankLine[] Array of subtable lines
161  // */
162  // public $lines = array();
163 
164 
165 
171  public function __construct(DoliDB $db)
172  {
173  global $conf, $langs;
174 
175  $this->db = $db;
176 
177  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
178  $this->fields['rowid']['visible'] = 0;
179  }
180  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
181  $this->fields['entity']['enabled'] = 0;
182  }
183 
184  // Example to show how to set values of fields definition dynamically
185  /*if ($user->rights->hrm->skillrank->read) {
186  $this->fields['myfield']['visible'] = 1;
187  $this->fields['myfield']['noteditable'] = 0;
188  }*/
189 
190  // Unset fields that are disabled
191  foreach ($this->fields as $key => $val) {
192  if (isset($val['enabled']) && empty($val['enabled'])) {
193  unset($this->fields[$key]);
194  }
195  }
196 
197  // Translate some data of arrayofkeyval
198  if (is_object($langs)) {
199  foreach ($this->fields as $key => $val) {
200  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
201  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
202  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
203  }
204  }
205  }
206  }
207  }
208 
216  public function create(User $user, $notrigger = false)
217  {
218  global $langs;
219 
220  $sqlfilter = 'fk_object='.((int) $this->fk_object)." AND objecttype='".$this->db->escape($this->objecttype)."' AND fk_skill = ".((int) $this->fk_skill);
221  $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, array('customsql' => $sqlfilter));
222  if (!empty($alreadyLinked)) {
223  $this->error = $langs->trans('ErrSkillAlreadyAdded');
224  return -1;
225  }
226 
227  $resultcreate = $this->createCommon($user, $notrigger);
228 
229  return $resultcreate;
230  }
231 
239  public function createFromClone(User $user, $fromid)
240  {
241  global $langs, $extrafields;
242  $error = 0;
243 
244  dol_syslog(__METHOD__, LOG_DEBUG);
245 
246  $object = new self($this->db);
247 
248  $this->db->begin();
249 
250  // Load source object
251  $result = $object->fetchCommon($fromid);
252  if ($result > 0 && !empty($object->table_element_line)) {
253  $object->fetchLines();
254  }
255 
256  // get lines so they will be clone
257  //foreach($this->lines as $line)
258  // $line->fetch_optionals();
259 
260  // Reset some properties
261  unset($object->id);
262  unset($object->fk_user_creat);
263  unset($object->import_key);
264 
265  // Clear fields
266  if (property_exists($object, 'ref')) {
267  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
268  }
269  if (property_exists($object, 'label')) {
270  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
271  }
272  if (property_exists($object, 'status')) {
273  $object->status = self::STATUS_DRAFT;
274  }
275  if (property_exists($object, 'date_creation')) {
276  $object->date_creation = dol_now();
277  }
278  if (property_exists($object, 'date_modification')) {
279  $object->date_modification = null;
280  }
281  // ...
282  // Clear extrafields that are unique
283  if (is_array($object->array_options) && count($object->array_options) > 0) {
284  $extrafields->fetch_name_optionals_label($this->table_element);
285  foreach ($object->array_options as $key => $option) {
286  $shortkey = preg_replace('/options_/', '', $key);
287  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
288  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
289  unset($object->array_options[$key]);
290  }
291  }
292  }
293 
294  // Create clone
295  $object->context['createfromclone'] = 'createfromclone';
296  $result = $object->createCommon($user);
297  if ($result < 0) {
298  $error++;
299  $this->error = $object->error;
300  $this->errors = $object->errors;
301  }
302 
303  if (!$error) {
304  // copy internal contacts
305  if ($this->copy_linked_contact($object, 'internal') < 0) {
306  $error++;
307  }
308  }
309 
310  if (!$error) {
311  // copy external contacts if same company
312  if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
313  if ($this->copy_linked_contact($object, 'external') < 0) {
314  $error++;
315  }
316  }
317  }
318 
319  unset($object->context['createfromclone']);
320 
321  // End
322  if (!$error) {
323  $this->db->commit();
324  return $object;
325  } else {
326  $this->db->rollback();
327  return -1;
328  }
329  }
330 
338  public function fetch($id, $ref = null)
339  {
340  $result = $this->fetchCommon($id, $ref);
341  if ($result > 0 && !empty($this->table_element_line)) {
342  $this->fetchLines();
343  }
344  return $result;
345  }
346 
352  public function fetchLines()
353  {
354  $this->lines = array();
355 
356  $result = $this->fetchLinesCommon();
357  return $result;
358  }
359 
368  public function cloneFromCurrentSkill($currentSkill, $fk_user)
369  {
370 
371  global $user;
372 
373  $this->fk_skill = $currentSkill->fk_skill;
374  $this->rankorder = $currentSkill->rankorder;
375  $this->fk_object = $fk_user;
376  $this->date_creation = dol_now();
377  $this->fk_user_creat = $user->id;
378  $this->fk_user_modif = $user->id;
379  $this->objecttype = self::SKILLRANK_TYPE_USER;
380  $result = $this->create($user);
381 
382  return $result;
383  }
384 
396  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
397  {
398  global $conf;
399 
400  dol_syslog(__METHOD__, LOG_DEBUG);
401 
402  $records = array();
403 
404  $sql = 'SELECT ';
405  $sql .= $this->getFieldList('t');
406  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
407  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
408  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
409  } else {
410  $sql .= ' WHERE 1 = 1';
411  }
412  // Manage filter
413  $sqlwhere = array();
414  if (count($filter) > 0) {
415  foreach ($filter as $key => $value) {
416  if ($key == 't.rowid') {
417  $sqlwhere[] = $key." = ".((int) $value);
418  } elseif ($key != 'customsql' && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
419  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
420  } elseif ($key == 'customsql') {
421  $sqlwhere[] = $value;
422  } elseif (strpos($value, '%') === false) {
423  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
424  } else {
425  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
426  }
427  }
428  }
429  if (count($sqlwhere) > 0) {
430  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
431  }
432 
433  if (!empty($sortfield)) {
434  $sql .= $this->db->order($sortfield, $sortorder);
435  }
436  if (!empty($limit)) {
437  $sql .= ' '.$this->db->plimit($limit, $offset);
438  }
439 
440  $resql = $this->db->query($sql);
441  if ($resql) {
442  $num = $this->db->num_rows($resql);
443  $i = 0;
444  while ($i < ($limit ? min($limit, $num) : $num)) {
445  $obj = $this->db->fetch_object($resql);
446 
447  $record = new self($this->db);
448  $record->setVarsFromFetchObj($obj);
449 
450  $records[$record->id] = $record;
451 
452  $i++;
453  }
454  $this->db->free($resql);
455 
456  return $records;
457  } else {
458  $this->errors[] = 'Error '.$this->db->lasterror();
459  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
460 
461  return -1;
462  }
463  }
464 
472  public function update(User $user, $notrigger = false)
473  {
474  return $this->updateCommon($user, $notrigger);
475  }
476 
484  public function delete(User $user, $notrigger = false)
485  {
486  return $this->deleteCommon($user, $notrigger);
487  //return $this->deleteCommon($user, $notrigger, 1);
488  }
489 
498  public function deleteLine(User $user, $idline, $notrigger = false)
499  {
500  if ($this->status < 0) {
501  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
502  return -2;
503  }
504 
505  return $this->deleteLineCommon($user, $idline, $notrigger);
506  }
507 
508 
516  public function validate($user, $notrigger = 0)
517  {
518  global $conf, $langs;
519 
520  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
521 
522  $error = 0;
523 
524  // Protection
525  if ($this->status == self::STATUS_VALIDATED) {
526  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
527  return 0;
528  }
529 
530  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skillrank->write))
531  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->skillrank->skillrank_advance->validate))))
532  {
533  $this->error='NotEnoughPermissions';
534  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
535  return -1;
536  }*/
537 
538  $now = dol_now();
539 
540  $this->db->begin();
541 
542  // Define new ref
543  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
544  $num = $this->getNextNumRef();
545  } else {
546  $num = $this->ref;
547  }
548  $this->newref = $num;
549 
550  if (!empty($num)) {
551  // Validate
552  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
553  $sql .= " SET ref = '".$this->db->escape($num)."',";
554  $sql .= " status = ".self::STATUS_VALIDATED;
555  if (!empty($this->fields['date_validation'])) {
556  $sql .= ", date_validation = '".$this->db->idate($now)."'";
557  }
558  if (!empty($this->fields['fk_user_valid'])) {
559  $sql .= ", fk_user_valid = ".((int) $user->id);
560  }
561  $sql .= " WHERE rowid = ".((int) $this->id);
562 
563  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
564  $resql = $this->db->query($sql);
565  if (!$resql) {
566  dol_print_error($this->db);
567  $this->error = $this->db->lasterror();
568  $error++;
569  }
570 
571  if (!$error && !$notrigger) {
572  // Call trigger
573  $result = $this->call_trigger('SKILLRANK_VALIDATE', $user);
574  if ($result < 0) {
575  $error++;
576  }
577  // End call triggers
578  }
579  }
580 
581  if (!$error) {
582  $this->oldref = $this->ref;
583 
584  // Rename directory if dir was a temporary ref
585  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
586  // Now we rename also files into index
587  $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)."'";
588  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
589  $resql = $this->db->query($sql);
590  if (!$resql) {
591  $error++; $this->error = $this->db->lasterror();
592  }
593 
594  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
595  $oldref = dol_sanitizeFileName($this->ref);
596  $newref = dol_sanitizeFileName($num);
597  $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
598  $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
599  if (!$error && file_exists($dirsource)) {
600  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
601 
602  if (@rename($dirsource, $dirdest)) {
603  dol_syslog("Rename ok");
604  // Rename docs starting with $oldref with $newref
605  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
606  foreach ($listoffiles as $fileentry) {
607  $dirsource = $fileentry['name'];
608  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
609  $dirsource = $fileentry['path'].'/'.$dirsource;
610  $dirdest = $fileentry['path'].'/'.$dirdest;
611  @rename($dirsource, $dirdest);
612  }
613  }
614  }
615  }
616  }
617 
618  // Set new ref and current status
619  if (!$error) {
620  $this->ref = $num;
621  $this->status = self::STATUS_VALIDATED;
622  }
623 
624  if (!$error) {
625  $this->db->commit();
626  return 1;
627  } else {
628  $this->db->rollback();
629  return -1;
630  }
631  }
632 
633 
641  public function setDraft($user, $notrigger = 0)
642  {
643  // Protection
644  if ($this->status <= self::STATUS_DRAFT) {
645  return 0;
646  }
647 
648  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
649  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
650  {
651  $this->error='Permission denied';
652  return -1;
653  }*/
654 
655  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
656  }
657 
665  public function cancel($user, $notrigger = 0)
666  {
667  // Protection
668  if ($this->status != self::STATUS_VALIDATED) {
669  return 0;
670  }
671 
672  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
673  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
674  {
675  $this->error='Permission denied';
676  return -1;
677  }*/
678 
679  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
680  }
681 
689  public function reopen($user, $notrigger = 0)
690  {
691  // Protection
692  if ($this->status != self::STATUS_CANCELED) {
693  return 0;
694  }
695 
696  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->write))
697  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->hrm->hrm_advance->validate))))
698  {
699  $this->error='Permission denied';
700  return -1;
701  }*/
702 
703  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
704  }
705 
716  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
717  {
718  global $conf, $langs, $hookmanager;
719 
720  if (!empty($conf->dol_no_mouse_hover)) {
721  $notooltip = 1; // Force disable tooltips
722  }
723 
724  $result = '';
725 
726  $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
727  if (isset($this->status)) {
728  $label .= ' '.$this->getLibStatut(5);
729  }
730  $label .= '<br>';
731  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
732 
733  $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
734 
735  if ($option != 'nolink') {
736  // Add param to save lastsearch_values or not
737  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
738  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
739  $add_save_lastsearch_values = 1;
740  }
741  if ($add_save_lastsearch_values) {
742  $url .= '&save_lastsearch_values=1';
743  }
744  }
745 
746  $linkclose = '';
747  if (empty($notooltip)) {
748  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
749  $label = $langs->trans("ShowSkillRank");
750  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
751  }
752  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
753  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
754  } else {
755  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
756  }
757 
758  if ($option == 'nolink') {
759  $linkstart = '<span';
760  } else {
761  $linkstart = '<a href="'.$url.'"';
762  }
763  $linkstart .= $linkclose.'>';
764  if ($option == 'nolink') {
765  $linkend = '</span>';
766  } else {
767  $linkend = '</a>';
768  }
769 
770  $result .= $linkstart;
771 
772  if (empty($this->showphoto_on_popup)) {
773  if ($withpicto) {
774  $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);
775  }
776  } else {
777  if ($withpicto) {
778  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
779 
780  list($class, $module) = explode('@', $this->picto);
781  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
782  $filearray = dol_dir_list($upload_dir, "files");
783  $filename = $filearray[0]['name'];
784  if (!empty($filename)) {
785  $pospoint = strpos($filearray[0]['name'], '.');
786 
787  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
788  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
789  $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>';
790  } else {
791  $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>';
792  }
793 
794  $result .= '</div>';
795  } else {
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  }
799  }
800 
801  if ($withpicto != 2) {
802  $result .= $this->ref;
803  }
804 
805  $result .= $linkend;
806  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
807 
808  global $action, $hookmanager;
809  $hookmanager->initHooks(array('skillrankdao'));
810  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
811  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
812  if ($reshook > 0) {
813  $result = $hookmanager->resPrint;
814  } else {
815  $result .= $hookmanager->resPrint;
816  }
817 
818  return $result;
819  }
820 
827  public function getLibStatut($mode = 0)
828  {
829  return $this->LibStatut($this->status, $mode);
830  }
831 
832  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840  public function LibStatut($status, $mode = 0)
841  {
842  // phpcs:enable
843  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
844  global $langs;
845  //$langs->load("hrm");
846  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
847  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
848  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
849  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
850  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
851  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
852  }
853 
854  $statusType = 'status'.$status;
855  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
856  if ($status == self::STATUS_CANCELED) {
857  $statusType = 'status6';
858  }
859 
860  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
861  }
862 
869  public function info($id)
870  {
871  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
872  $sql .= ' fk_user_creat, fk_user_modif';
873  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
874  $sql .= ' WHERE t.rowid = '.((int) $id);
875  $result = $this->db->query($sql);
876  if ($result) {
877  if ($this->db->num_rows($result)) {
878  $obj = $this->db->fetch_object($result);
879  $this->id = $obj->rowid;
880 
881  $this->user_creation_id = $obj->fk_user_creat;
882  $this->user_modification_id = $obj->fk_user_modif;
883  $this->date_creation = $this->db->jdate($obj->datec);
884  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
885  }
886 
887  $this->db->free($result);
888  } else {
889  dol_print_error($this->db);
890  }
891  }
892 
899  public function initAsSpecimen()
900  {
901  // Set here init that are not commonf fields
902  // $this->property1 = ...
903  // $this->property2 = ...
904 
905  $this->initAsSpecimenCommon();
906  }
907 
913  public function getLinesArray()
914  {
915  $this->lines = array();
916 
917  /*
918  $objectline = new SkillRankLine($this->db);
919  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_skillrank = '.((int) $this->id)));
920 
921  if (is_numeric($result)) {
922  $this->error = $this->error;
923  $this->errors = $this->errors;
924  return $result;
925  } else {
926  $this->lines = $result;
927  return $this->lines;
928  }
929  */
930  }
931 
937  public function getNextNumRef()
938  {
939  global $langs, $conf;
940  $langs->load("hrm");
941 
942  if (empty($conf->global->hrm_SKILLRANK_ADDON)) {
943  $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
944  }
945 
946  if (!empty($conf->global->hrm_SKILLRANK_ADDON)) {
947  $mybool = false;
948 
949  $file = $conf->global->hrm_SKILLRANK_ADDON.".php";
950  $classname = $conf->global->hrm_SKILLRANK_ADDON;
951 
952  // Include file with class
953  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
954  foreach ($dirmodels as $reldir) {
955  $dir = dol_buildpath($reldir."core/modules/hrm/");
956 
957  // Load file with numbering class (if found)
958  $mybool |= @include_once $dir.$file;
959  }
960 
961  if ($mybool === false) {
962  dol_print_error('', "Failed to include file ".$file);
963  return '';
964  }
965 
966  if (class_exists($classname)) {
967  $obj = new $classname();
968  $numref = $obj->getNextValue($this);
969 
970  if ($numref != '' && $numref != '-1') {
971  return $numref;
972  } else {
973  $this->error = $obj->error;
974  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
975  return "";
976  }
977  } else {
978  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
979  return "";
980  }
981  } else {
982  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
983  return "";
984  }
985  }
986 
998  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
999  {
1000  global $conf, $langs;
1001 
1002  $result = 0;
1003  $includedocgeneration = 0;
1004 
1005  $langs->load("hrm");
1006 
1007  if (!dol_strlen($modele)) {
1008  $modele = 'standard_skillrank';
1009 
1010  if (!empty($this->model_pdf)) {
1011  $modele = $this->model_pdf;
1012  } elseif (!empty($conf->global->SKILLRANK_ADDON_PDF)) {
1013  $modele = $conf->global->SKILLRANK_ADDON_PDF;
1014  }
1015  }
1016 
1017  $modelpath = "core/modules/hrm/doc/";
1018 
1019  if ($includedocgeneration && !empty($modele)) {
1020  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1021  }
1022 
1023  return $result;
1024  }
1025 
1033  public function doScheduledJob()
1034  {
1035  global $conf, $langs;
1036 
1037  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1038 
1039  $error = 0;
1040  $this->output = '';
1041  $this->error = '';
1042 
1043  dol_syslog(__METHOD__, LOG_DEBUG);
1044 
1045  $now = dol_now();
1046 
1047  $this->db->begin();
1048 
1049  // ...
1050 
1051  $this->db->commit();
1052 
1053  return $error;
1054  }
1055 
1066  // public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
1067  // {
1068  // if ($key == "rank") {
1069  // return displayRankInfos($this);
1070  // } else return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
1071  // }
1072 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
SkillRank\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: skillrank.class.php:641
db
$conf db
API class for accounts.
Definition: inc.php:41
SkillRank\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: skillrank.class.php:396
SkillRank\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: skillrank.class.php:1033
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
SkillRank\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: skillrank.class.php:827
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
SkillRank\getLinesArray
getLinesArray()
Create an array of lines.
Definition: skillrank.class.php:913
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
ref
$object ref
Definition: info.php:77
SkillRank\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: skillrank.class.php:239
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
SkillRank\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: skillrank.class.php:716
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
SkillRank\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: skillrank.class.php:899
SkillRank\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: skillrank.class.php:338
SkillRank\cloneFromCurrentSkill
cloneFromCurrentSkill($currentSkill, $fk_user)
Clone skillrank Object linked to job with user id The skillrank table is a join table that is marked ...
Definition: skillrank.class.php:368
SkillRank\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: skillrank.class.php:840
SkillRank\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: skillrank.class.php:498
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
SkillRank\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: skillrank.class.php:352
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
SkillRank\validate
validate($user, $notrigger=0)
Validate object.
Definition: skillrank.class.php:516
SkillRank\create
create(User $user, $notrigger=false)
Create object into database.
Definition: skillrank.class.php:216
SkillRank\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: skillrank.class.php:665
SkillRank\info
info($id)
Load the info information in the object.
Definition: skillrank.class.php:869
User
Class to manage Dolibarr users.
Definition: user.class.php:44
SkillRank\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: skillrank.class.php:689
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
SkillRank\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: skillrank.class.php:937
SkillRank\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: skillrank.class.php:998
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
SkillRank
Class for SkillRank.
Definition: skillrank.class.php:35
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987
SkillRank\__construct
__construct(DoliDB $db)
Constructor.
Definition: skillrank.class.php:171
SkillRank\update
update(User $user, $notrigger=false)
Update object into database.
Definition: skillrank.class.php:472