/** * Returns grouped search results * * @param string $string * @return array */ public function getGroupedResults($string) { $search = $this->getResults($string); // empty key array contains all data $result = array('' => array('count' => 0, 'class' => '', 'config' => array(), 'icon' => '', 'label' => '')); /** @var $item Item */ foreach ($search->getElements() as $item) { $config = $item->getEntityConfig(); $alias = $config['alias']; if (!isset($result[$alias])) { $group = array('count' => 0, 'class' => $item->getEntityName(), 'config' => $config, 'icon' => '', 'label' => ''); if (!empty($group['class']) && $this->configManager->hasConfig($group['class'])) { $entityConfigId = new EntityConfigId('entity', $group['class']); $entityConfig = $this->configManager->getConfig($entityConfigId); if ($entityConfig->has('plural_label')) { $group['label'] = $this->translator->trans($entityConfig->get('plural_label')); } if ($entityConfig->has('icon')) { $group['icon'] = $entityConfig->get('icon'); } } $result[$alias] = $group; } $result[$alias]['count']++; $result['']['count']++; } uasort($result, function ($first, $second) { if ($first['label'] == $second['label']) { return 0; } return $first['label'] > $second['label'] ? 1 : -1; }); return $result; }
/** * {@inheritdoc} */ public function getViewValue($value) { switch ($value['type']) { case AbstractDateFilterType::TYPE_MORE_THAN: return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_more_than'), $this->formatter->formatDate($value['start'])); case AbstractDateFilterType::TYPE_LESS_THAN: return sprintf('%s %s', $this->translator->trans('oro.filter.form.label_date_type_less_than'), $this->formatter->formatDate($value['end'])); } return sprintf('%s - %s', $this->formatter->formatDate($value['start']), $this->formatter->formatDate($value['end'])); }
/** * @param string $className * @param array $originalFieldNames * @return array */ protected function getReverseRelationTypes($className, array &$originalFieldNames) { $extendProvider = $this->configManager->getProvider('extend'); $entityConfig = $extendProvider->getConfig($className); $entityProvider = $this->configManager->getProvider('entity'); $result = []; if ($entityConfig->is('relation')) { $relations = $entityConfig->get('relation'); foreach ($relations as $relationKey => $relation) { if (!$this->isAvailableRelation($extendProvider, $relation, $relationKey)) { continue; } /** @var FieldConfigId $fieldId */ $fieldId = $relation['field_id']; /** @var FieldConfigId $targetFieldId */ $targetFieldId = $relation['target_field_id']; $entityLabel = $entityProvider->getConfig($targetFieldId->getClassName())->get('label'); $fieldLabel = $entityProvider->getConfigById($targetFieldId)->get('label'); $fieldName = $fieldId ? $fieldId->getFieldName() : ''; $maxFieldNameLength = $this->nameGenerator->getMaxCustomEntityFieldNameSize(); if (strlen($fieldName) > $maxFieldNameLength) { $cutFieldName = substr($fieldName, 0, $maxFieldNameLength); $originalFieldNames[$cutFieldName] = $fieldName; $fieldName = $cutFieldName; } $key = $relationKey . '||' . $fieldName; $result[$key] = $this->translator->trans(self::TYPE_LABEL_PREFIX . 'inverse_relation', ['%entity_name%' => $this->translator->trans($entityLabel), '%field_name%' => $this->translator->trans($fieldLabel)]); } } return $result; }
/** * @param string $className * @return null|string */ protected function getClassLabel($className) { if (!$this->configManager->hasConfig($className)) { return null; } $entityConfig = new EntityConfigId('entity', $className); $label = $this->configManager->getConfig($entityConfig)->get('label'); return $this->translator->trans($label); }
protected function applyFormBlockConfigTranslations(array &$config) { foreach ($config as $key => &$val) { if (is_array($val)) { $this->applyFormBlockConfigTranslations($val); } elseif (is_string($val) && $key === 'title' && !empty($val)) { $val = $this->translator->trans($val); } } }
/** * Checks if the given template contains several parts and if so translate each part individually * * @param string $translatedTemplate * @param array $params */ protected function translateTitleParts(&$translatedTemplate, array $params) { if ($translatedTemplate) { $delimiter = ' ' . $this->userConfigManager->get('oro_navigation.title_delimiter') . ' '; $transItems = explode($delimiter, $translatedTemplate); foreach ($transItems as $key => $transItem) { $transItems[$key] = $this->translator->trans($transItem, $params); } $translatedTemplate = implode($delimiter, $transItems); } }
/** * @param FormEvent $event */ public function postSubmit(FormEvent $event) { $form = $event->getForm(); $configModel = $form->getConfig()->getOption('config_model'); $data = $event->getData(); $labelsToBeUpdated = []; foreach ($this->configManager->getProviders() as $provider) { $scope = $provider->getScope(); if (isset($data[$scope])) { $configId = $this->configManager->getConfigIdByModel($configModel, $scope); $config = $provider->getConfigById($configId); $translatable = $provider->getPropertyConfig()->getTranslatableValues($configId); foreach ($data[$scope] as $code => $value) { if (in_array($code, $translatable, true)) { // check if a label text was changed $labelKey = $config->get($code); if (!$configModel->getId()) { $labelsToBeUpdated[$labelKey] = $value; } elseif ($value != $this->translator->trans($labelKey)) { $labelsToBeUpdated[$labelKey] = $value; } // replace label text with label name in $value variable $value = $config->get($code); } $config->set($code, $value); } $this->configManager->persist($config); } } if ($form->isValid()) { // update changed labels if any if (!empty($labelsToBeUpdated)) { /** @var EntityManager $translationEm */ $translationEm = $this->doctrine->getManagerForClass(Translation::ENTITY_NAME); /** @var TranslationRepository $translationRepo */ $translationRepo = $translationEm->getRepository(Translation::ENTITY_NAME); $values = []; $locale = $this->translator->getLocale(); foreach ($labelsToBeUpdated as $labelKey => $labelText) { // save into translation table $values[] = $translationRepo->saveValue($labelKey, $labelText, $locale, TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI); } // mark translation cache dirty $this->dbTranslationMetadataCache->updateTimestamp($locale); $translationEm->flush($values); } $this->configManager->flush(); } }
/** * @param WidgetOptionBag $widgetOptions * @param $getterName * @param $dataType * @param bool $lessIsBetter * @return array */ public function getBigNumberValues(WidgetOptionBag $widgetOptions, $getterName, $dataType, $lessIsBetter = false) { $lessIsBetter = (bool) $lessIsBetter; $result = []; $dateRange = $widgetOptions->get('dateRange'); $value = $this->{$getterName}($dateRange); $result['value'] = $this->formatValue($value, $dataType); $previousInterval = $widgetOptions->get('usePreviousInterval', []); if (count($previousInterval)) { $pastResult = $this->{$getterName}($previousInterval); $result['deviation'] = $this->translator->trans('orocrm.magento.dashboard.e_commerce_statistic.no_changes'); $deviation = $value - $pastResult; if ($pastResult != 0 && $dataType !== 'percent') { if ($deviation != 0) { $deviationPercent = $deviation / $pastResult; $result['deviation'] = sprintf('%s (%s)', $this->formatValue($deviation, $dataType, true), $this->formatValue($deviationPercent, 'percent', true)); if (!$lessIsBetter) { $result['isPositive'] = $deviation > 0; } else { $result['isPositive'] = !($deviation > 0); } } } else { if (round($deviation * 100, 0) != 0) { $result['deviation'] = $this->formatValue($deviation, $dataType, true); if (!$lessIsBetter) { $result['isPositive'] = $deviation > 0; } else { $result['isPositive'] = !($deviation > 0); } } } $result['previousRange'] = sprintf('%s - %s', $this->dateTimeFormatter->formatDate($previousInterval['start']), $this->dateTimeFormatter->formatDate($previousInterval['end'])); } return $result; }
/** * Get total row frontend data * * @param array $rowConfig Total row config * @param array $data Db result data for current total row config * @return array Array with array of columns total values and labels */ protected function getTotalData($rowConfig, $data) { $totalData = []; if (!empty($data)) { $totalData['columns'] = []; foreach ($rowConfig['columns'] as $field => $total) { $totalData['columns'][$field] = []; if (isset($data[$field])) { $totalValue = $data[$field]; if (isset($total[Configuration::TOTALS_FORMATTER_KEY])) { $totalValue = $this->applyFrontendFormatting($totalValue, $total[Configuration::TOTALS_FORMATTER_KEY]); } $totalData['columns'][$field]['total'] = $totalValue; } if (isset($total[Configuration::TOTALS_LABEL_KEY])) { $totalData['columns'][$field][Configuration::TOTALS_LABEL_KEY] = $this->translator->trans($total[Configuration::TOTALS_LABEL_KEY]); } } } return $totalData; }