From 92c4eed7c68eb6322e5ce294688b0f3f6340f718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 11 Feb 2023 21:34:21 +0100 Subject: [PATCH] add ajax tooltip on knowledge record --- htdocs/core/ajax/ajaxtooltip.php | 4 ++ .../class/knowledgerecord.class.php | 59 +++++++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/htdocs/core/ajax/ajaxtooltip.php b/htdocs/core/ajax/ajaxtooltip.php index 60220a221ff..3933f03533b 100644 --- a/htdocs/core/ajax/ajaxtooltip.php +++ b/htdocs/core/ajax/ajaxtooltip.php @@ -163,6 +163,10 @@ if ($objecttype == 'facture' || $objecttype == 'invoice') { $classpath = 'opensurvey/class'; $module = 'opensurvey'; $myobject = 'opensurveysondage'; +} elseif ($objecttype == 'knowledgerecord') { + $classpath = 'knowledgemanagement/class'; + $module = 'knowledgemanagement'; + $myobject = 'knowledgerecord'; } // Generic case for $classfile and $classname diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php index 3f9f1b40223..d5cd5a82a51 100644 --- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php +++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php @@ -129,7 +129,15 @@ class KnowledgeRecord extends CommonObject public $fk_user_valid; public $import_key; public $model_pdf; + + /** + * @var string question asked + */ public $question; + + /** + * @var string answer to question + */ public $answer; public $url; public $status; @@ -265,8 +273,8 @@ class KnowledgeRecord extends CommonObject if (property_exists($object, 'ref')) { $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default']; } - if (property_exists($object, 'label')) { - $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default']; + if (property_exists($object, 'question')) { + $object->question = empty($this->fields['question']['default']) ? $langs->trans("CopyOf")." ".$object->question : $this->fields['question']['default']; } if (property_exists($object, 'status')) { $object->status = self::STATUS_DRAFT; @@ -706,6 +714,32 @@ class KnowledgeRecord extends CommonObject return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'KNOWLEDGERECORD_REOPEN'); } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $conf, $langs; + + $langs->loadLangs(['knowledgemanagement', 'languages']); + + $datas = []; + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("KnowledgeRecord").''; + if (isset($this->statut)) { + $datas['picto'] .= ' '.$this->getLibStatut(5); + } + $datas['label'] = '
'.$langs->trans('Ref').': '.$this->ref; + $datas['question'] = '
'.$langs->trans('Question').': '.$this->question; + $labellang = ($this->lang ? $langs->trans('Language_'.$this->lang) : ''); + $datas['lang'] = '
'.$langs->trans('Language').': ' . picto_from_langcode($this->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang; + + return $datas; + } + /** * Return a link to the object card (with optionaly the picto) * @@ -726,12 +760,17 @@ class KnowledgeRecord extends CommonObject $result = ''; - $label = img_picto('', $this->picto).' '.$langs->trans("KnowledgeRecord").''; - if (isset($this->status)) { - $label .= ' '.$this->getLibStatut(5); + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + ]; + $classfortooltip = 'classfortooltip'; + $dataparams = ''; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $classfortooltip = 'classforajaxtooltip'; + $dataparams = ' data-params='.json_encode($params); } - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$this->ref; + $label = implode($this->getTooltipContentArray($params)); $url = dol_buildpath('/knowledgemanagement/knowledgerecord_card.php', 1).'?id='.$this->id; @@ -752,8 +791,8 @@ class KnowledgeRecord extends CommonObject $label = $langs->trans("ShowKnowledgeRecord"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + $linkclose .= $dataparams.' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; } else { $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); } @@ -774,7 +813,7 @@ class KnowledgeRecord extends CommonObject if (empty($this->showphoto_on_popup)) { if ($withpicto) { - $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); + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } } else { if ($withpicto) {