/**
  * @param BuildBefore $event
  * @return bool
  */
 public function onBuildBefore(BuildBefore $event)
 {
     $datagrid = $event->getDatagrid();
     $config = $event->getConfig();
     $entityClassName = $datagrid->getParameters()->get('class_name');
     $fieldName = $datagrid->getParameters()->get('field_name');
     $entityId = $datagrid->getParameters()->get('id');
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $extendFieldConfig = $extendConfigProvider->getConfig($entityClassName, $fieldName);
     $targetEntityName = $extendFieldConfig->get('target_entity');
     $targetFieldNames = $extendFieldConfig->get('target_grid');
     // build 'assigned' field expression
     if ($entityId) {
         $extendEntityConfig = $extendConfigProvider->getConfig($entityClassName);
         $relations = $extendEntityConfig->get('relation');
         $relation = $relations[$extendFieldConfig->get('relation_key')];
         $targetFieldName = $relation['target_field_id']->getFieldName();
         $fieldType = $extendFieldConfig->getId()->getFieldType();
         $operator = $fieldType == 'oneToMany' ? '=' : 'MEMBER OF';
         $whenExpr = '(:relation ' . $operator . ' o.' . $targetFieldName . ' OR o.id IN (:data_in))' . ' AND o.id NOT IN (:data_not_in)';
     } else {
         $whenExpr = 'o.id IN (:data_in) AND o.id NOT IN (:data_not_in)';
     }
     $assignedExpr = "CASE WHEN " . $whenExpr . " THEN true ELSE false END";
     // build a query skeleton
     $query = ['select' => ['o.id', $assignedExpr . ' as assigned'], 'from' => [['table' => $targetEntityName, 'alias' => 'o']]];
     $config->offsetSetByPath('[source][query]', $query);
     // enable AdditionalFieldsExtension to add all other fields
     $config->offsetSetByPath('[options][entity_name]', $targetEntityName);
     $config->offsetSetByPath('[options][additional_fields]', $targetFieldNames);
 }
 /**
  * {@inheritdoc}
  */
 public function getEntityAlias($entityClass)
 {
     if ($this->configManager->hasConfig($entityClass)) {
         // check for enums
         $enumCode = $this->configManager->getProvider('enum')->getConfig($entityClass)->get('code');
         if ($enumCode) {
             $entityAlias = $this->getEntityAliasFromConfig($entityClass);
             if (null !== $entityAlias) {
                 return $entityAlias;
             }
             return $this->createEntityAlias(str_replace('_', '', $enumCode));
         }
         // check for dictionaries
         $groups = $this->configManager->getProvider('grouping')->getConfig($entityClass)->get('groups');
         if (!empty($groups) && in_array(GroupingScope::GROUP_DICTIONARY, $groups, true)) {
             // delegate aliases generation to default provider
             return null;
         }
         // exclude hidden entities
         if ($this->configManager->isHiddenModel($entityClass)) {
             return false;
         }
         // check for custom entities
         if (ExtendHelper::isCustomEntity($entityClass)) {
             $entityAlias = $this->getEntityAliasFromConfig($entityClass);
             if (null !== $entityAlias) {
                 return $entityAlias;
             }
             return $this->createEntityAlias('Extend' . ExtendHelper::getShortClassName($entityClass));
         }
     }
     return null;
 }
 /**
  * Options:
  * - grid_name - name of grid that will be used for entity selection
  * - grid_parameters - parameters need to be passed to grid request
  * - grid_render_parameters - render parameters need to be set for grid rendering
  * - existing_entity_grid_id - grid row field name used as entity identifier
  * - create_enabled - enables new entity creation
  * - create_acl - ACL resource used to determine that create is allowed, by default CREATE for entity used
  * - create_form_route - route name for creation form
  * - create_form_route_parameters - route parameters for create_form_route_parameters
  *
  * {@inheritDoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(['existing_entity_grid_id' => 'id', 'create_enabled' => true, 'create_acl' => null, 'create_form_route' => null, 'create_form_route_parameters' => [], 'grid_name' => null, 'grid_parameters' => [], 'grid_render_parameters' => []]);
     $resolver->setNormalizers(['create_enabled' => function (Options $options, $createEnabled) {
         $createRouteName = $options->get('create_form_route');
         $createEnabled = $createEnabled && !empty($createRouteName);
         if ($createEnabled) {
             $aclName = $options->get('create_acl');
             if (empty($aclName)) {
                 $aclObjectName = 'Entity:' . $options->get('entity_class');
                 $createEnabled = $this->securityFacade->isGranted('CREATE', $aclObjectName);
             } else {
                 $createEnabled = $this->securityFacade->isGranted($aclName);
             }
         }
         return $createEnabled;
     }, 'grid_name' => function (Options $options, $gridName) {
         if (!empty($gridName)) {
             return $gridName;
         }
         $formConfig = $this->configManager->getProvider('form')->getConfig($options->get('entity_class'));
         if ($formConfig->has('grid_name')) {
             return $formConfig->get('grid_name');
         }
         throw new InvalidConfigurationException('The option "grid_name" must be set.');
     }]);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $configModel = $options['config_model'];
     $data = array();
     if ($configModel instanceof FieldConfigModel) {
         $className = $configModel->getEntity()->getClassName();
         $fieldName = $configModel->getFieldName();
         $fieldType = $configModel->getType();
         $configType = PropertyConfigContainer::TYPE_FIELD;
     } else {
         $className = $configModel->getClassName();
         $fieldName = null;
         $fieldType = null;
         $configType = PropertyConfigContainer::TYPE_ENTITY;
     }
     foreach ($this->configManager->getProviders() as $provider) {
         if ($provider->getPropertyConfig()->hasForm($configType, $fieldType)) {
             $config = $provider->getConfig($className, $fieldName);
             $builder->add($provider->getScope(), new ConfigScopeType($provider->getPropertyConfig()->getFormItems($configType, $fieldType), $config, $this->configManager, $configModel), array('block_config' => (array) $provider->getPropertyConfig()->getFormBlockConfig($configType)));
             $data[$provider->getScope()] = $config->all();
         }
     }
     if ($fieldType == 'optionSet') {
         $data['extend']['set_options'] = $this->configManager->getEntityManager()->getRepository(OptionSet::ENTITY_NAME)->findOptionsByField($configModel->getId());
     }
     $builder->setData($data);
     $builder->addEventSubscriber(new ConfigSubscriber($this->configManager));
 }
Ejemplo n.º 5
0
 protected function getEntityChoiceList($entityClassName, $relationType)
 {
     $choices = array();
     $extendEntityConfig = $this->configManager->getProvider('extend');
     /** @var EntityConfigId[] $entityIds */
     $entityIds = $this->targetEntity ? array($extendEntityConfig->getId($this->targetEntity)) : $extendEntityConfig->getIds();
     if (in_array($relationType, array(RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY))) {
         $entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
             $config = $this->configManager->getConfig($configId);
             return $config->is('is_extend');
         });
     }
     $entityIds = array_filter($entityIds, function (EntityConfigId $configId) {
         $config = $this->configManager->getConfig($configId);
         return $config->is('is_extend', false) || !$config->is('state', ExtendScope::STATE_NEW);
     });
     foreach ($entityIds as $entityId) {
         $className = $entityId->getClassName();
         if ($className != $entityClassName) {
             $entityConfig = $this->configManager->getProvider('entity')->getConfig($className);
             $choices[$className] = new ChoiceListItem($entityConfig->get('label'), array('data-icon' => $entityConfig->get('icon')));
         }
     }
     return $choices;
 }
Ejemplo n.º 6
0
 public function testFlush()
 {
     $model = new EntityConfigModel(self::ENTITY_CLASS);
     $entityConfigId = new EntityConfigId('entity', self::ENTITY_CLASS);
     $entityConfig = new Config($entityConfigId);
     $entityConfig->set('icon', 'test_icon');
     $entityConfig->set('label', 'test_label');
     $entityPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['indexed' => true]]]]]);
     $this->entityConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($entityPropertyConfig));
     $testConfigId = new EntityConfigId('test', self::ENTITY_CLASS);
     $testConfig = new Config($testConfigId);
     $testConfig->set('attr1', 'test_attr1');
     $testPropertyConfig = new PropertyConfigContainer(['entity' => ['items' => ['attr1' => []]]]);
     $this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($testPropertyConfig));
     $this->modelManager->expects($this->once())->method('getEntityModel')->with($entityConfigId->getClassName())->will($this->returnValue($model));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->modelManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($em));
     $this->setFlushExpectations($em, [$model]);
     $this->eventDispatcher->expects($this->at(2))->method('dispatch')->with(Events::PRE_FLUSH, new PreFlushConfigEvent(['entity' => $entityConfig, 'test' => $testConfig], $this->configManager));
     $this->configManager->persist($entityConfig);
     $this->configManager->persist($testConfig);
     $this->configManager->flush();
     $this->assertEquals(['icon' => 'test_icon', 'label' => 'test_label'], $model->toArray('entity'));
     $this->assertEquals(['attr1' => 'test_attr1'], $model->toArray('test'));
     $this->assertCount(3, $model->getIndexedValues());
     $this->assertEquals('entity_config', $model->getIndexedValues()[0]->getScope());
     $this->assertEquals('module_name', $model->getIndexedValues()[0]->getCode());
     $this->assertEquals('entity_config', $model->getIndexedValues()[1]->getScope());
     $this->assertEquals('entity_name', $model->getIndexedValues()[1]->getCode());
     $this->assertEquals('entity', $model->getIndexedValues()[2]->getScope());
     $this->assertEquals('label', $model->getIndexedValues()[2]->getCode());
 }
 /**
  * {@inheritdoc}
  */
 public function getConfiguration()
 {
     $configuration = parent::getConfiguration();
     $className = $this->source->getEntity();
     $metadata = $this->configManager->getEntityMetadata($className);
     if (!$metadata || empty($metadata->routeView)) {
         return $configuration;
     }
     $fromPart = $configuration->offsetGetByPath('[source][query][from]');
     $entityAlias = null;
     $doctrineMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
     $identifiers = $doctrineMetadata->getIdentifier();
     $primaryKey = array_shift($identifiers);
     foreach ($fromPart as $piece) {
         if ($piece['table'] == $className) {
             $entityAlias = $piece['alias'];
             break;
         }
     }
     if (!$entityAlias || !$primaryKey || count($identifiers) > 1 || !$this->isActionSupported($primaryKey)) {
         return $configuration;
     }
     $viewAction = ['view' => ['type' => 'navigate', 'label' => 'oro.report.datagrid.view', 'acl_resource' => 'VIEW;entity:' . $className, 'icon' => 'eye-open', 'link' => 'view_link', 'rowAction' => true]];
     $properties = [$primaryKey => null, 'view_link' => ['type' => 'url', 'route' => $metadata->routeView, 'params' => [$primaryKey]]];
     $configuration->offsetAddToArrayByPath('[source][query][select]', ["{$entityAlias}.{$primaryKey}"]);
     $configuration->offsetAddToArrayByPath('[properties]', $properties);
     $configuration->offsetAddToArrayByPath('[actions]', $viewAction);
     return $configuration;
 }
Ejemplo n.º 8
0
 /**
  * Generate doctrine proxy classes for extended entities
  */
 public function generateProxies()
 {
     $em = $this->configManager->getEntityManager();
     $isAutoGenerated = $em->getConfiguration()->getAutoGenerateProxyClasses();
     if (!$isAutoGenerated) {
         $proxyDir = $em->getConfiguration()->getProxyDir();
         if (!empty($this->cacheDir) && $this->kernelCacheDir !== $this->cacheDir && strpos($proxyDir, $this->kernelCacheDir) === 0) {
             $proxyDir = $this->cacheDir . substr($proxyDir, strlen($this->kernelCacheDir));
         }
         $extendConfigProvider = $this->configManager->getProvider('extend');
         $extendConfigs = $extendConfigProvider->getConfigs(null, true);
         $metadataFactory = $em->getMetadataFactory();
         $proxyFactory = $em->getProxyFactory();
         foreach ($extendConfigs as $extendConfig) {
             if (!$extendConfig->is('is_extend')) {
                 continue;
             }
             if ($extendConfig->in('state', [ExtendScope::STATE_NEW])) {
                 continue;
             }
             $entityClass = $extendConfig->getId()->getClassName();
             $proxyFileName = $proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $entityClass) . '.php';
             $metadata = $metadataFactory->getMetadataFor($entityClass);
             $proxyFactory->generateProxyClasses([$metadata], $proxyDir);
             clearstatcache(true, $proxyFileName);
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Returns objects extracted from simple search
  *
  * @param User $user
  * @param string $entityClass
  * @param string $searchString
  * @param int $offset
  * @param int $maxResults
  *
  * @return array
  */
 protected function getObjects(User $user, $entityClass, $searchString, $offset, $maxResults)
 {
     $objects = [];
     if (!$this->configManager->hasConfig($entityClass)) {
         return $objects;
     }
     $classNames = $this->shareScopeProvider->getClassNamesBySharingScopeConfig($entityClass);
     if (!$classNames) {
         return $objects;
     }
     $tables = [];
     foreach ($classNames as $className) {
         $metadata = $this->em->getClassMetadata($className);
         $tables[] = $metadata->getTableName();
     }
     $searchResults = $this->indexer->simpleSearch($searchString, $offset, $maxResults, $tables);
     list($userIds, $buIds, $orgIds) = $this->getIdsByClass($searchResults, $user);
     if ($orgIds) {
         $organizations = $this->em->getRepository('OroOrganizationBundle:Organization')->getEnabledOrganizations($orgIds);
         $objects = array_merge($objects, $organizations);
     }
     if ($buIds) {
         $businessUnits = $this->em->getRepository('OroOrganizationBundle:BusinessUnit')->getBusinessUnits($buIds);
         $objects = array_merge($objects, $businessUnits);
     }
     if ($userIds) {
         $users = $this->em->getRepository('OroUserBundle:User')->findUsersByIds($userIds);
         $objects = array_merge($objects, $users);
     }
     return $objects;
 }
Ejemplo n.º 10
0
 /**
  * @return ConfigProvider
  */
 protected function getExtendConfigProvider()
 {
     if (!$this->extendConfigProvider) {
         $this->extendConfigProvider = $this->configManager->getProvider('extend');
     }
     return $this->extendConfigProvider;
 }
Ejemplo n.º 11
0
 /**
  * POST_SUBMIT event handler
  *
  * @param FormEvent $event
  */
 public function postSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $options = $form->getConfig()->getOptions();
     /** @var ConfigIdInterface $configId */
     $configId = $options['config_id'];
     if (!$form->isValid()) {
         return;
     }
     // change the entity state to "Requires update" if the attribute has "require_schema_update" option
     // and the value of the attribute was changed
     $configProvider = $this->configManager->getProvider($configId->getScope());
     if ($configProvider->getPropertyConfig()->isSchemaUpdateRequired($form->getName(), $configId)) {
         $newVal = $form->getData();
         $oldVal = $this->configManager->getConfig($configId)->get($form->getName());
         if ($this->isSchemaUpdateRequired($newVal, $oldVal)) {
             $extendConfigProvider = $this->configManager->getProvider('extend');
             $extendConfig = $extendConfigProvider->getConfig($configId->getClassName());
             if ($extendConfig->is('state', ExtendScope::STATE_ACTIVE)) {
                 $extendConfig->set('state', ExtendScope::STATE_UPDATE);
                 $this->configManager->persist($extendConfig);
             }
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $vars = ['configs' => $options['configs']];
     if ($form->getData()) {
         $data = $form->getParent()->getData();
         $fieldConfig = $this->cm->getProvider('extend')->getConfig($data, $form->getName());
         if ($form->getData()) {
             /** @var ConverterInterface|EntitySelectHandler $converter */
             $converter = $options['converter'];
             $result = [];
             if ($converter instanceof EntitySelectHandler) {
                 $converter->initForEntity($fieldConfig->getId()->getClassName(), $fieldConfig->get('target_field'));
             }
             if (isset($options['configs']['multiple']) && $options['configs']['multiple']) {
                 foreach ($form->getData() as $item) {
                     $result[] = $converter->convertItem($item);
                 }
             } else {
                 $result[] = $converter->convertItem($form->getData());
             }
             $vars['attr'] = ['data-selected-data' => json_encode($result)];
         }
     }
     $view->vars = array_replace_recursive($view->vars, $vars);
 }
 /**
  * {@inheritdoc}
  */
 public function preUpdate()
 {
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $entityConfigs = $extendConfigProvider->getConfigs();
     foreach ($entityConfigs as $entityConfig) {
         if (!$entityConfig->is('is_extend')) {
             continue;
         }
         $fieldConfigs = $extendConfigProvider->getConfigs($entityConfig->getId()->getClassName());
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->is('state', ExtendScope::STATE_NEW)) {
                 continue;
             }
             /** @var FieldConfigId $fieldConfigId */
             $fieldConfigId = $fieldConfig->getId();
             if (in_array($fieldConfigId->getFieldType(), ['file', 'image'])) {
                 // create a relation
                 $relationKey = $this->relationBuilder->addManyToOneRelation($entityConfig, 'Oro\\Bundle\\AttachmentBundle\\Entity\\File', $fieldConfigId->getFieldName(), 'id', ['importexport' => ['process_as_scalar' => true]], $fieldConfigId->getFieldType());
                 // set cascade persist
                 $relations = $entityConfig->get('relation');
                 $cascade = isset($relations[$relationKey]['cascade']) ? $relations[$relationKey]['cascade'] : [];
                 $cascade[] = 'persist';
                 $relations[$relationKey]['cascade'] = $cascade;
                 $entityConfig->set('relation', $relations);
                 $extendConfigProvider->persist($entityConfig);
             }
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * @param LoggerInterface $logger
  * @param bool            $dryRun
  */
 protected function runActivityLists(LoggerInterface $logger, $dryRun = false)
 {
     // @todo: this workaround should be removed in BAP-9156
     $this->configManager->clear();
     $targetEntities = $this->provider->getTargetEntityClasses(false);
     $toSchema = clone $this->schema;
     $hasSchemaChanges = false;
     foreach ($targetEntities as $targetEntity) {
         $associationName = ExtendHelper::buildAssociationName($targetEntity, ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
         $relationTableName = $this->nameGenerator->generateManyToManyJoinTableName(ActivityListEntityConfigDumperExtension::ENTITY_CLASS, $associationName, $targetEntity);
         if (!$toSchema->hasTable($relationTableName)) {
             $hasSchemaChanges = true;
             $this->activityListExtension->addActivityListAssociation($toSchema, $this->metadataHelper->getTableNameByEntityClass($targetEntity));
         }
     }
     if ($hasSchemaChanges) {
         $comparator = new Comparator();
         $platform = $this->connection->getDatabasePlatform();
         $schemaDiff = $comparator->compare($this->schema, $toSchema);
         $queries = $schemaDiff->toSql($platform);
         foreach ($queries as $query) {
             $this->logQuery($logger, $query);
             if (!$dryRun) {
                 $this->connection->executeQuery($query);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function preUpdate()
 {
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $entityConfigs = $extendConfigProvider->getConfigs();
     foreach ($entityConfigs as $entityConfig) {
         if (!$entityConfig->is('is_extend')) {
             continue;
         }
         $fieldConfigs = $extendConfigProvider->getConfigs($entityConfig->getId()->getClassName());
         foreach ($fieldConfigs as $fieldConfig) {
             if (!$fieldConfig->in('state', [ExtendScope::STATE_NEW, ExtendScope::STATE_UPDATE])) {
                 continue;
             }
             /** @var FieldConfigId $fieldConfigId */
             $fieldConfigId = $fieldConfig->getId();
             if (in_array($fieldConfigId->getFieldType(), ['file', 'image'])) {
                 $cascade = $fieldConfig->get('cascade', false, []);
                 if (!in_array('persist', $cascade, true)) {
                     $cascade[] = 'persist';
                 }
                 $this->relationBuilder->addManyToOneRelation($entityConfig, 'Oro\\Bundle\\AttachmentBundle\\Entity\\File', $fieldConfigId->getFieldName(), 'id', ['extend' => ['cascade' => $cascade], 'importexport' => ['process_as_scalar' => true]], $fieldConfigId->getFieldType());
             }
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $configModel = $options['config_model'];
     $data = array();
     if ($configModel instanceof FieldConfigModel) {
         $className = $configModel->getEntity()->getClassName();
         $fieldName = $configModel->getFieldName();
         $fieldType = $configModel->getType();
         $configType = PropertyConfigContainer::TYPE_FIELD;
         /**
          * Add read only field name and field type
          */
         $builder->add('fieldName', 'text', array('label' => 'oro.entity_config.form.name.label', 'block' => 'general', 'disabled' => true, 'data' => $fieldName));
         $builder->add('type', 'choice', array('label' => 'oro.entity_config.form.type.label', 'choices' => [], 'block' => 'general', 'disabled' => true, 'empty_value' => 'oro.entity_extend.form.data_type.' . $fieldType));
     } else {
         $className = $configModel->getClassName();
         $fieldName = null;
         $fieldType = null;
         $configType = PropertyConfigContainer::TYPE_ENTITY;
     }
     foreach ($this->configManager->getProviders() as $provider) {
         if ($provider->getPropertyConfig()->hasForm($configType, $fieldType)) {
             $config = $this->configManager->getConfig($provider->getId($className, $fieldName, $fieldType));
             $builder->add($provider->getScope(), new ConfigScopeType($provider->getPropertyConfig()->getFormItems($configType, $fieldType), $config, $this->configManager, $configModel), array('block_config' => $this->getFormBlockConfig($provider, $configType)));
             $data[$provider->getScope()] = $config->all();
         }
     }
     $builder->setData($data);
     $builder->addEventSubscriber(new ConfigSubscriber($this->doctrine, $this->configManager, $this->translator, $this->dbTranslationMetadataCache));
 }
 /**
  * {@inheritdoc}
  */
 public function preUpdate()
 {
     $ownershipConfigProvider = $this->configManager->getProvider('ownership');
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $entityConfigs = $extendConfigProvider->getConfigs();
     foreach ($entityConfigs as $entityConfig) {
         if (!$entityConfig->is('owner', ExtendScope::OWNER_CUSTOM)) {
             continue;
         }
         if (!$entityConfig->is('state', ExtendScope::STATE_NEW)) {
             continue;
         }
         if (!$ownershipConfigProvider->hasConfig($entityConfig->getId()->getClassName())) {
             continue;
         }
         $ownershipConfig = $ownershipConfigProvider->getConfig($entityConfig->getId()->getClassName());
         $ownerType = $ownershipConfig->get('owner_type');
         if (empty($ownerType)) {
             continue;
         }
         $this->createOwnerRelation($entityConfig, $this->getOwnerTargetEntityClassName($ownerType), $ownershipConfig->get('owner_field_name'));
         if (in_array($ownerType, [OwnershipType::OWNER_TYPE_USER, OwnershipType::OWNER_TYPE_BUSINESS_UNIT]) && $ownershipConfig->has('organization_field_name')) {
             $this->createOwnerRelation($entityConfig, $this->ownershipMetadataProvider->getOrganizationClass(), $ownershipConfig->get('organization_field_name'));
         }
     }
 }
Ejemplo n.º 18
0
 /**
  * @param ConfigureMenuEvent $event
  */
 public function onNavigationConfigure(ConfigureMenuEvent $event)
 {
     $menu = $event->getMenu();
     $children = array();
     $entitiesMenuItem = $menu->getChild('system_tab')->getChild('entities_list');
     if ($entitiesMenuItem) {
         /** @var ConfigProvider $entityConfigProvider */
         $entityConfigProvider = $this->configManager->getProvider('entity');
         /** @var ConfigProvider $entityExtendProvider */
         $entityExtendProvider = $this->configManager->getProvider('extend');
         $extendConfigs = $entityExtendProvider->getConfigs();
         foreach ($extendConfigs as $extendConfig) {
             if ($this->checkAvailability($extendConfig)) {
                 $config = $entityConfigProvider->getConfig($extendConfig->getId()->getClassname());
                 if (!class_exists($config->getId()->getClassName()) || !$this->securityFacade->hasLoggedUser() || !$this->securityFacade->isGranted('VIEW', 'entity:' . $config->getId()->getClassName())) {
                     continue;
                 }
                 $children[$config->get('label')] = array('label' => $this->translator->trans($config->get('label')), 'options' => array('route' => 'oro_entity_index', 'routeParameters' => array('entityName' => str_replace('\\', '_', $config->getId()->getClassName())), 'extras' => array('safe_label' => true, 'routes' => array('oro_entity_*'))));
             }
         }
         sort($children);
         foreach ($children as $child) {
             $entitiesMenuItem->addChild($child['label'], $child['options']);
         }
     }
 }
Ejemplo n.º 19
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;
 }
 /**
  *
  * @param  string $scope
  * @return array
  */
 protected function getObjectName($scope = 'name')
 {
     if (empty($this->filterChoices[$scope])) {
         $alias = 'ce';
         $qb = $this->configManager->getEntityManager()->createQueryBuilder();
         $qb->select($alias)->from(EntityConfigModel::ENTITY_NAME, $alias)->add('select', $alias . '.className')->distinct($alias . '.className');
         $result = $qb->getQuery()->getArrayResult();
         $options = ['name' => [], 'module' => []];
         foreach ((array) $result as $value) {
             $className = explode('\\', $value['className']);
             $options['name'][$value['className']] = '';
             $options['module'][$value['className']] = '';
             if (strpos($value['className'], 'Extend\\Entity') === false) {
                 foreach ($className as $index => $name) {
                     if (count($className) - 1 == $index) {
                         $options['name'][$value['className']] = $name;
                     } elseif (!in_array($name, array('Bundle', 'Entity'))) {
                         $options['module'][$value['className']] .= $name;
                     }
                 }
             } else {
                 $options['name'][$value['className']] = str_replace('Extend\\Entity\\', '', $value['className']);
                 $options['module'][$value['className']] = 'System';
             }
         }
         $this->filterChoices = $options;
     }
     return $this->filterChoices[$scope];
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('fieldName', 'text', array('label' => 'Field Name', 'block' => 'type'));
     $entityProvider = $this->configManager->getProvider('entity');
     $extendProvider = $this->configManager->getProvider('extend');
     $entityConfig = $extendProvider->getConfig($options['class_name']);
     if ($entityConfig->is('relation')) {
         $types = array();
         foreach ($entityConfig->get('relation') as $relationKey => $relation) {
             $fieldId = $relation['field_id'];
             $targetFieldId = $relation['target_field_id'];
             if (!$relation['assign'] || !$targetFieldId) {
                 continue;
             }
             if ($fieldId && $extendProvider->hasConfigById($fieldId) && !$extendProvider->getConfigById($fieldId)->is('state', ExtendManager::STATE_DELETED)) {
                 continue;
             }
             $entityLabel = $entityProvider->getConfig($targetFieldId->getClassName())->get('label');
             $fieldLabel = $entityProvider->getConfigById($targetFieldId)->get('label');
             $key = $relationKey . '||' . ($fieldId ? $fieldId->getFieldName() : '');
             $types[$key] = 'Relation (' . $entityLabel . ') ' . $fieldLabel;
         }
         $this->types = array_merge($this->types, $types);
     }
     $builder->add('type', 'choice', array('choices' => $this->types, 'empty_value' => 'Please choice type...', 'block' => 'type'));
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function isApplicableField($className, $fieldName)
 {
     $fieldModel = $this->configManager->getConfigFieldModel($className, $fieldName);
     if (!$fieldModel) {
         // this serializer works with non configurable entities as well
         return true;
     }
     if ($fieldModel->getMode() === ConfigModelManager::MODE_HIDDEN) {
         // exclude hidden fields
         return false;
     }
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $extendConfig = $extendConfigProvider->getConfig($className, $fieldName);
     if (!$this->allowExtendedFields && $extendConfig->is('is_extend')) {
         // exclude extended fields if it is requested
         return false;
     }
     if ($extendConfig->is('is_deleted') || $extendConfig->is('state', ExtendScope::STATE_NEW)) {
         // exclude deleted and not created yet fields
         return false;
     }
     if ($extendConfig->has('target_entity') && $extendConfigProvider->getConfig($extendConfig->get('target_entity'))->is('is_deleted')) {
         // exclude associations with deleted custom entities
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 /**
  * @param $className
  *
  * @return null|string
  */
 public function getGridName($className)
 {
     $className = $this->entityClassNameHelper->resolveEntityClass($className);
     if (!$this->configManager->hasConfig($className)) {
         return null;
     }
     return $this->configManager->getProvider('security')->getConfig($className)->get('share_grid');
 }
Ejemplo n.º 24
0
 /**
  * Returns a value of 'immutable' attribute for the given entity/field
  *
  * @param string      $scope
  * @param string      $className
  * @param string|null $fieldName
  *
  * @return mixed The returned value depends on a scope, for example in some scopes it can be only boolean,
  *               but other scopes can allow to use either boolean or array. More details can be found
  *               in corresponding entity_config.yml
  */
 public function getImmutable($scope, $className, $fieldName = null)
 {
     $configProvider = $this->configManager->getProvider($scope);
     if ($configProvider->hasConfig($className, $fieldName)) {
         return $configProvider->getConfig($className, $fieldName)->get('immutable');
     }
     return null;
 }
 /**
  * Check if an association between a given entity type and attachments is ready to be used in a business logic.
  * It means that the association should exist and should not be marked as deleted.
  *
  * @param string $entityClass The target entity class
  *
  * @return bool
  */
 protected function isAttachmentAssociationAccessible($entityClass)
 {
     $associationName = ExtendHelper::buildAssociationName($entityClass);
     if (!$this->configManager->hasConfig(self::ATTACHMENT_ENTITY, $associationName)) {
         return false;
     }
     return ExtendHelper::isFieldAccessible($this->configManager->getFieldConfig('extend', self::ATTACHMENT_ENTITY, $associationName));
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     if (!$this->configManager->hasConfig($metadata->name, $associationName)) {
         return false;
     }
     $extendFieldConfig = $this->configManager->getFieldConfig('extend', $metadata->name, $associationName);
     return !ExtendHelper::isFieldAccessible($extendFieldConfig) || $this->configManager->isHiddenModel($metadata->name, $associationName) || $extendFieldConfig->has('target_entity') && !ExtendHelper::isEntityAccessible($this->configManager->getEntityConfig('extend', $extendFieldConfig->get('target_entity')));
 }
 /**
  * {@inheritdoc}
  */
 public function up(Schema $schema, QueryBag $queries)
 {
     $this->configManager->flushAllCaches();
     if ($schema instanceof ExtendSchema) {
         $queries->addQuery(new RefreshExtendConfigMigrationQuery($this->commandExecutor, $this->dataStorageExtension->get('initial_entity_config_state', []), $this->initialEntityConfigStatePath));
         $queries->addQuery(new RefreshExtendCacheMigrationQuery($this->commandExecutor));
     }
 }
Ejemplo n.º 28
0
 /**
  * @param string $className The entity class name
  * @param string $attrName  The entity config attribute name
  * @param string $scope     The entity config scope name
  *
  * @return mixed
  */
 public function getClassConfigValue($className, $attrName, $scope = 'entity')
 {
     if (!$this->configManager->hasConfig($className)) {
         return null;
     }
     $entityConfig = new EntityConfigId($scope, $className);
     return $this->configManager->getConfig($entityConfig)->get($attrName);
 }
Ejemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->config = $this->configManager->getProvider('extend')->getConfigById($options['config_id']);
     $this->formFactory = $builder->getFormFactory();
     $builder->add('target_entity', new TargetType($this->configManager, $options['config_id']), ['constraints' => [new Assert\NotBlank()]]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'preSubmitData']);
     $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'preSubmitData']);
 }
Ejemplo n.º 30
0
 /**
  * Check if an association between a given entity type and activity type is ready to be used in a business logic.
  * It means that the association should exist and should not be marked as deleted.
  *
  * @param string $entityClass   The target entity class
  * @param string $activityClass The activity entity class
  *
  * @return bool
  */
 protected function isActivityAssociationAccessible($entityClass, $activityClass)
 {
     $associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);
     if (!$this->configManager->hasConfig($activityClass, $associationName)) {
         return false;
     }
     return ExtendHelper::isFieldAccessible($this->configManager->getFieldConfig('extend', $activityClass, $associationName));
 }