dolibarr  18.0.6
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 (!isModEnabled('multicompany') && 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->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('HRM_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  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'skillrank/".$this->db->escape($this->newref)."'";
594  $sql .= " WHERE filepath = 'skillrank/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
595  $resql = $this->db->query($sql);
596  if (!$resql) {
597  $error++; $this->error = $this->db->lasterror();
598  }
599 
600  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
601  $oldref = dol_sanitizeFileName($this->ref);
602  $newref = dol_sanitizeFileName($num);
603  $dirsource = $conf->hrm->dir_output.'/skillrank/'.$oldref;
604  $dirdest = $conf->hrm->dir_output.'/skillrank/'.$newref;
605  if (!$error && file_exists($dirsource)) {
606  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
607 
608  if (@rename($dirsource, $dirdest)) {
609  dol_syslog("Rename ok");
610  // Rename docs starting with $oldref with $newref
611  $listoffiles = dol_dir_list($conf->hrm->dir_output.'/skillrank/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
612  foreach ($listoffiles as $fileentry) {
613  $dirsource = $fileentry['name'];
614  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
615  $dirsource = $fileentry['path'].'/'.$dirsource;
616  $dirdest = $fileentry['path'].'/'.$dirdest;
617  @rename($dirsource, $dirdest);
618  }
619  }
620  }
621  }
622  }
623 
624  // Set new ref and current status
625  if (!$error) {
626  $this->ref = $num;
627  $this->status = self::STATUS_VALIDATED;
628  }
629 
630  if (!$error) {
631  $this->db->commit();
632  return 1;
633  } else {
634  $this->db->rollback();
635  return -1;
636  }
637  }
638 
639 
647  public function setDraft($user, $notrigger = 0)
648  {
649  // Protection
650  if ($this->status <= self::STATUS_DRAFT) {
651  return 0;
652  }
653 
654  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
655  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
656  {
657  $this->error='Permission denied';
658  return -1;
659  }*/
660 
661  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SKILLRANK_UNVALIDATE');
662  }
663 
671  public function cancel($user, $notrigger = 0)
672  {
673  // Protection
674  if ($this->status != self::STATUS_VALIDATED) {
675  return 0;
676  }
677 
678  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
679  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
680  {
681  $this->error='Permission denied';
682  return -1;
683  }*/
684 
685  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'SKILLRANK_CANCEL');
686  }
687 
695  public function reopen($user, $notrigger = 0)
696  {
697  // Protection
698  if ($this->status != self::STATUS_CANCELED) {
699  return 0;
700  }
701 
702  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->write))
703  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->hrm->hrm_advance->validate))))
704  {
705  $this->error='Permission denied';
706  return -1;
707  }*/
708 
709  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'SKILLRANK_REOPEN');
710  }
711 
722  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
723  {
724  global $conf, $langs, $hookmanager;
725 
726  if (!empty($conf->dol_no_mouse_hover)) {
727  $notooltip = 1; // Force disable tooltips
728  }
729 
730  $result = '';
731 
732  $label = img_picto('', $this->picto).' <u>'.$langs->trans("SkillRank").'</u>';
733  if (isset($this->status)) {
734  $label .= ' '.$this->getLibStatut(5);
735  }
736  $label .= '<br>';
737  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
738 
739  $url = dol_buildpath('/hrm/skillrank_card.php', 1).'?id='.$this->id;
740 
741  if ($option != 'nolink') {
742  // Add param to save lastsearch_values or not
743  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
744  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
745  $add_save_lastsearch_values = 1;
746  }
747  if ($add_save_lastsearch_values) {
748  $url .= '&save_lastsearch_values=1';
749  }
750  }
751 
752  $linkclose = '';
753  if (empty($notooltip)) {
754  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
755  $label = $langs->trans("ShowSkillRank");
756  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
757  }
758  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
759  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
760  } else {
761  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
762  }
763 
764  if ($option == 'nolink') {
765  $linkstart = '<span';
766  } else {
767  $linkstart = '<a href="'.$url.'"';
768  }
769  $linkstart .= $linkclose.'>';
770  if ($option == 'nolink') {
771  $linkend = '</span>';
772  } else {
773  $linkend = '</a>';
774  }
775 
776  $result .= $linkstart;
777 
778  if (empty($this->showphoto_on_popup)) {
779  if ($withpicto) {
780  $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);
781  }
782  } else {
783  if ($withpicto) {
784  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
785 
786  list($class, $module) = explode('@', $this->picto);
787  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
788  $filearray = dol_dir_list($upload_dir, "files");
789  $filename = $filearray[0]['name'];
790  if (!empty($filename)) {
791  $pospoint = strpos($filearray[0]['name'], '.');
792 
793  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
794  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
795  $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>';
796  } else {
797  $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>';
798  }
799 
800  $result .= '</div>';
801  } else {
802  $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);
803  }
804  }
805  }
806 
807  if ($withpicto != 2) {
808  $result .= $this->ref;
809  }
810 
811  $result .= $linkend;
812  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
813 
814  global $action, $hookmanager;
815  $hookmanager->initHooks(array('skillrankdao'));
816  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
817  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
818  if ($reshook > 0) {
819  $result = $hookmanager->resPrint;
820  } else {
821  $result .= $hookmanager->resPrint;
822  }
823 
824  return $result;
825  }
826 
833  public function getLibStatut($mode = 0)
834  {
835  return $this->LibStatut($this->status, $mode);
836  }
837 
838  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
846  public function LibStatut($status, $mode = 0)
847  {
848  // phpcs:enable
849  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
850  global $langs;
851  //$langs->load("hrm");
852  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
853  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
854  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
855  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
856  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
857  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
858  }
859 
860  $statusType = 'status'.$status;
861  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
862  if ($status == self::STATUS_CANCELED) {
863  $statusType = 'status6';
864  }
865 
866  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
867  }
868 
875  public function info($id)
876  {
877  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
878  $sql .= ' fk_user_creat, fk_user_modif';
879  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
880  $sql .= ' WHERE t.rowid = '.((int) $id);
881  $result = $this->db->query($sql);
882  if ($result) {
883  if ($this->db->num_rows($result)) {
884  $obj = $this->db->fetch_object($result);
885  $this->id = $obj->rowid;
886 
887  $this->user_creation_id = $obj->fk_user_creat;
888  $this->user_modification_id = $obj->fk_user_modif;
889  $this->date_creation = $this->db->jdate($obj->datec);
890  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
891  }
892 
893  $this->db->free($result);
894  } else {
895  dol_print_error($this->db);
896  }
897  }
898 
905  public function initAsSpecimen()
906  {
907  // Set here init that are not commonf fields
908  // $this->property1 = ...
909  // $this->property2 = ...
910 
911  $this->initAsSpecimenCommon();
912  }
913 
919  public function getLinesArray()
920  {
921  $this->lines = array();
922 
923  /*
924  $objectline = new SkillRankLine($this->db);
925  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_skillrank = '.((int) $this->id)));
926 
927  if (is_numeric($result)) {
928  $this->error = $objectline->error;
929  $this->errors = $objectline->errors;
930  return $result;
931  } else {
932  $this->lines = $result;
933  return $this->lines;
934  }
935  */
936 
937  return $this->lines;
938  }
939 
945  public function getNextNumRef()
946  {
947  global $langs, $conf;
948  $langs->load("hrm");
949 
950  if (empty($conf->global->hrm_SKILLRANK_ADDON)) {
951  $conf->global->hrm_SKILLRANK_ADDON = 'mod_skillrank_standard';
952  }
953 
954  if (!empty($conf->global->hrm_SKILLRANK_ADDON)) {
955  $mybool = false;
956 
957  $file = $conf->global->hrm_SKILLRANK_ADDON.".php";
958  $classname = $conf->global->hrm_SKILLRANK_ADDON;
959 
960  // Include file with class
961  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
962  foreach ($dirmodels as $reldir) {
963  $dir = dol_buildpath($reldir."core/modules/hrm/");
964 
965  // Load file with numbering class (if found)
966  $mybool |= @include_once $dir.$file;
967  }
968 
969  if ($mybool === false) {
970  dol_print_error('', "Failed to include file ".$file);
971  return '';
972  }
973 
974  if (class_exists($classname)) {
975  $obj = new $classname();
976  $numref = $obj->getNextValue($this);
977 
978  if ($numref != '' && $numref != '-1') {
979  return $numref;
980  } else {
981  $this->error = $obj->error;
982  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
983  return "";
984  }
985  } else {
986  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
987  return "";
988  }
989  } else {
990  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
991  return "";
992  }
993  }
994 
1006  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1007  {
1008  global $conf, $langs;
1009 
1010  $result = 0;
1011  $includedocgeneration = 0;
1012 
1013  $langs->load("hrm");
1014 
1015  if (!dol_strlen($modele)) {
1016  $modele = 'standard_skillrank';
1017 
1018  if (!empty($this->model_pdf)) {
1019  $modele = $this->model_pdf;
1020  } elseif (!empty($conf->global->SKILLRANK_ADDON_PDF)) {
1021  $modele = $conf->global->SKILLRANK_ADDON_PDF;
1022  }
1023  }
1024 
1025  $modelpath = "core/modules/hrm/doc/";
1026 
1027  if ($includedocgeneration && !empty($modele)) {
1028  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1029  }
1030 
1031  return $result;
1032  }
1033 
1041  public function doScheduledJob()
1042  {
1043  global $conf, $langs;
1044 
1045  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1046 
1047  $error = 0;
1048  $this->output = '';
1049  $this->error = '';
1050 
1051  dol_syslog(__METHOD__, LOG_DEBUG);
1052 
1053  $now = dol_now();
1054 
1055  $this->db->begin();
1056 
1057  // ...
1058 
1059  $this->db->commit();
1060 
1061  return $error;
1062  }
1063 
1074  // public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '')
1075  // {
1076  // if ($key == "rank") {
1077  // return displayRankInfos($this);
1078  // } else return parent::showOutputField($val, $key, $value, $moreparam, $keysuffix, $keyprefix, $morecss);
1079  // }
1080 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the 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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
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.
createFromClone(User $user, $fromid)
Clone an object into another one.
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.
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.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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)
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.