/** * @depends testMakeStringForMultipleLinks */ public function testMakeStringForLinkOrLinks() { $accounts = Account::getByName('account1'); $account1 = $accounts[0]; $account2 = $accounts[1]; $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS); $displayAttribute->setModelAliasUsingTableAliasName('abc'); $displayAttribute->attributeIndexOrDerivedType = 'name'; $reportResultsRowData = new ReportResultsRowData(array($displayAttribute), 4); $reportResultsRowData->addModelAndAlias($account2, 'abc'); $result = ReportResultsGridUtil::makeStringForLinkOrLinks('attribute0', $reportResultsRowData, true, 'account1'); $this->assertContains('<span class="tooltip">2</span>', $result); $result = ReportResultsGridUtil::makeStringForLinkOrLinks('attribute0', $reportResultsRowData, false, 'account1'); $this->assertContains('a target="new"', $result); $this->assertContains('id=' . $account2->id, $result); $this->assertNotContains('tooltip', $result); }
/** * Raw values such as those used by the header x-axis or y-axis rows/columns need to be translated. An example * is a dropdown where the value is the raw database value and needs to be properly translated for display. * Another example is dynamic __User, where the value is the user id, and needs to be stringified to the User * model. * @param $value * @return string */ public function resolveValueAsLabelForHeaderCell($value, $forExport = false) { $tContent = null; $translatedValue = $value; $resolvedAttribute = $this->getResolvedAttribute(); $displayElementType = $this->getDisplayElementType(); $modelToReportAdapter = $this->makeResolvedAttributeModelRelationsAndAttributesToReportAdapter(); if ($modelToReportAdapter->getModel()->isAttribute($resolvedAttribute) && $modelToReportAdapter->getModel()->isRelation($resolvedAttribute) && !$modelToReportAdapter->getModel()->isOwnedRelation($resolvedAttribute)) { $relationModelClassName = $modelToReportAdapter->getModel()->getRelationModelClassName($resolvedAttribute); $relatedModel = $relationModelClassName::getById((int) $value); if ($relatedModel->isAttribute('serializedLabels')) { $translatedValue = $relatedModel->resolveTranslatedNameByLanguage(Yii::app()->language); } } elseif ($displayElementType == 'User') { $user = User::getById((int) $value); $translatedValue = strval($user); } elseif ($displayElementType == 'DropDown') { $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->getResolvedAttributeModelClassName(), $this->getResolvedAttribute()); $dataAndLabels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language); if (isset($dataAndLabels[$value])) { $translatedValue = $dataAndLabels[$value]; } } elseif ($displayElementType == 'CheckBox') { if ($value) { $translatedValue = Zurmo::t('Core', 'Yes'); } elseif ($value == false && $value != '') { $translatedValue = Zurmo::t('Core', 'No'); } } elseif ($displayElementType == 'GroupByModifierMonth') { $translatedValue = DateTimeUtil::getMonthName($value); } if ($translatedValue === null) { $translatedValue = ''; } if ($this->isALinkableAttribute() && !$forExport) { $modelClassName = get_class($modelToReportAdapter->getModel()); $moduleClassName = $modelToReportAdapter->getModuleClassName(); if (isset($relationModelClassName)) { $modelClassName = $relationModelClassName; } return ReportResultsGridUtil::makeStringForMultipleLinks($value, $modelClassName, $moduleClassName); } return $translatedValue; }