コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * {@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']));
 }
コード例 #3
0
ファイル: FieldTypeTest.php プロジェクト: nmallare/platform
 protected function setUp()
 {
     parent::setUp();
     $this->configManagerMock = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->translatorMock = $this->getMockBuilder('Oro\\Bundle\\TranslationBundle\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $this->translatorMock->expects($this->any())->method('trans')->will($this->returnCallback(function ($param) {
         return $param;
     }));
     $this->type = new FieldType($this->configManagerMock, $this->translatorMock, new ExtendDbIdentifierNameGenerator());
     $this->typeReflection = new \ReflectionClass($this->type);
 }
コード例 #4
0
 /**
  * Creates instance of Translator
  *
  * @param $loader
  * @param array $options
  * @return Translator
  */
 public function getTranslator($loader, $options = [])
 {
     $translator = new Translator($this->getContainer($loader), new MessageSelector(), ['loader' => ['loader']], $options);
     $translator->addResource('loader', 'foo', 'fr');
     $translator->addResource('loader', 'foo', 'en');
     $translator->addResource('loader', 'foo', 'es');
     $translator->addResource('loader', 'foo', 'pt-PT');
     // European Portuguese
     $translator->addResource('loader', 'foo', 'pt_BR');
     // Brazilian Portuguese
     return $translator;
 }
コード例 #5
0
 /**
  * @param FormInterface $field
  * @param FormView $view
  */
 protected function updateTooltip(FormInterface $field, FormView $view)
 {
     $parentOptions = $field->getParent()->getConfig()->getOptions();
     $parentClassName = isset($parentOptions['data_class']) ? $parentOptions['data_class'] : null;
     if (!isset($view->vars['tooltip']) && $parentClassName && $this->entityConfigProvider->hasConfig($parentClassName, $field->getName())) {
         $tooltip = $this->entityConfigProvider->getConfig($parentClassName, $field->getName())->get('description');
         //@deprecated 1.9.0:1.11.0 tooltips.*.yml will be removed. Use Resources/translations/messages.*.yml instead
         if ($this->translator->hasTrans($tooltip, self::DEFAULT_TRANSLATE_DOMAIN) || $this->translator->hasTrans($tooltip, self::TOOLTIPS_TRANSLATE_DOMAIN)) {
             $view->vars['tooltip'] = $tooltip;
         }
     }
 }
コード例 #6
0
 /**
  * Combines JSON with js translation and renders js-resource
  *
  * @param array $domains
  * @param string $locale
  * @param bool $debug
  * @return string
  */
 public function renderJsTranslationContent(array $domains, $locale, $debug = false)
 {
     $domainsTranslations = $this->translator->getTranslations($domains, $locale);
     $result = ['locale' => $locale, 'defaultDomains' => $domains, 'messages' => []];
     if ($debug) {
         $result['debug'] = true;
     }
     foreach ($domainsTranslations as $domain => $translations) {
         $result['messages'] += array_combine(array_map(function ($id) use($domain) {
             return sprintf('%s:%s', $domain, $id);
         }, array_keys($translations)), array_values($translations));
     }
     return $this->templating->render($this->template, ['json' => $result]);
 }
コード例 #7
0
ファイル: FieldTypeTest.php プロジェクト: Maksold/platform
 protected function setUp()
 {
     parent::setUp();
     $this->configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->translator = $this->getMockBuilder('Oro\\Bundle\\TranslationBundle\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $this->translator->expects($this->any())->method('trans')->willReturnCallback(function ($id, $parameters) {
         if ($id === 'oro.entity_extend.form.data_type.inverse_relation') {
             return strtr('Reuse "%field_name%" of %entity_name%', $parameters);
         }
         return $id;
     });
     $this->fieldTypeProvider = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Provider\\FieldTypeProvider')->disableOriginalConstructor()->getMock();
     $this->fieldTypeProvider->expects($this->any())->method('getSupportedFieldTypes')->willReturn(array_keys($this->defaultFieldTypeChoices[self::FIELDS_GROUP]));
     $this->fieldTypeProvider->expects($this->any())->method('getSupportedRelationTypes')->willReturn(array_keys($this->defaultFieldTypeChoices[self::RELATIONS_GROUP]));
     $this->type = new FieldType($this->configManager, $this->translator, new ExtendDbIdentifierNameGenerator(), $this->fieldTypeProvider);
 }
コード例 #8
0
ファイル: FieldType.php プロジェクト: nmallare/platform
 /**
  * @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;
 }
コード例 #9
0
ファイル: Indexer.php プロジェクト: nmallare/platform
 /**
  * @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);
 }
コード例 #10
0
ファイル: ConfigType.php プロジェクト: ramunasd/platform
 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);
         }
     }
 }
コード例 #11
0
ファイル: TitleService.php プロジェクト: xamin123/platform
 /**
  * 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);
     }
 }
コード例 #12
0
ファイル: ConfigSubscriber.php プロジェクト: Maksold/platform
 /**
  * @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();
     }
 }
コード例 #13
0
ファイル: BigNumber.php プロジェクト: CopeX/crm
 /**
  * @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;
 }
コード例 #14
0
 /**
  * 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;
 }