oAttribute = $oAttribute; $this->oValue = $oValue; // Initialization $this->Init(); // UI Initialization $this->InitUI(); } /** * Initialization. * * @return void * @throws \Twig\Error\LoaderError */ private function Init() { // Link set model properties $this->sTargetClass = LinkSetModel::GetTargetClass($this->oAttribute); $sTargetField = LinkSetModel::GetTargetField($this->oAttribute); // Get objects from linked data $aObjectsData = []; LinkSetRepository::LinksDbSetToTargetObjectArray($this->oValue, false, $aObjectsData, $this->sTargetClass, $sTargetField); $this->aObjectsData = array_values($aObjectsData); // Twig environment $this->oTwigEnv = TwigHelper::GetTwigEnvironment(TwigHelper::ENUM_TEMPLATES_BASE_PATH_BACKOFFICE); $oAppContext = new ApplicationContext(); $this->sAppContext = $oAppContext->GetForLink(); $this->sUIPage = cmdbAbstractObject::ComputeStandardUIPage($this->sTargetClass); } /** * UI Initialization. * * @return void * @throws \Exception */ private function InitUI() { // Error handling if ($this->aObjectsData === null) { $sMessage = "Error while displaying attribute {$this->oAttribute->GetCode()}"; $this->AddSubBlock(HtmlFactory::MakeHtmlContent($sMessage)); return; } // Container $sHtml = ''; // Iterate throw data... foreach ($this->aObjectsData as $aItem) { // Ignore obsolete data if (!utils::ShowObsoleteData() && $aItem['obsolescence_flag']) { continue; } // Generate template $sTemplate = TwigHelper::RenderTemplate($this->oTwigEnv, $aItem, 'application/object/set/set_renderer'); // Friendly name $sFriendlyNameForHtml = utils::HtmlEntities($aItem['friendlyname']); // Full description $sFullDescriptionForHtml = utils::HtmlEntities($aItem['full_description']); // Append value $sHtml .= 'GenerateLinkUrl($aItem['key']).' class="attribute-set-item" data-label="'.$sFriendlyNameForHtml.'" data-tooltip-content="'.$sFullDescriptionForHtml.'" data-tooltip-html-enabled="true">'.$sTemplate.''; } // Close container $sHtml .= ''; // Make html block $this->AddSubBlock(HtmlFactory::MakeHtmlContent($sHtml)); } /** * GenerateLinkUrl. * * @param $id * * @return string * @throws \Exception */ private function GenerateLinkUrl($id): string { return ' href="' .utils::GetAbsoluteUrlAppRoot() ."pages/$this->sUIPage?operation=details&class=$this->sTargetClass&id=$id&$this->sAppContext" .'" target="_self"'; } }