/** * {@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; }
/** * @param string $entityClassName * @param string $relationType * * @return array */ protected function getEntityChoiceList($entityClassName, $relationType) { /** @var EntityConfigId[] $entityIds */ $entityIds = $this->targetEntityClass ? [$this->configManager->getId('extend', $this->targetEntityClass)] : $this->configManager->getIds('extend'); if (in_array($relationType, [RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY], true)) { $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('state', ExtendScope::STATE_NEW) && ($this->targetEntityClass || !$config->is('is_deleted')); }); $choices = []; foreach ($entityIds as $entityId) { $className = $entityId->getClassName(); if (!$this->configManager->hasConfig($className, 'id') && !ExtendHelper::isCustomEntity($className)) { // @todo: temporary ignore entities that don't have PK with name 'id' // remove this in https://magecore.atlassian.net/browse/BAP-9713 continue; } if ($className !== $entityClassName) { $entityConfig = $this->configManager->getProvider('entity')->getConfig($className); $choices[$className] = $entityConfig->get('label'); } } return $choices; }
/** * Checks if the form type should be read-only or not * * @param Options $options * * @return bool */ protected function isReadOnly($options) { /** @var ConfigIdInterface $configId */ $configId = $options['config_id']; $className = $configId->getClassName(); if (empty($className)) { return false; } $fieldName = $this->typeHelper->getFieldName($configId); if (empty($fieldName)) { return false; } if ($this->typeHelper->isSystem($className, $fieldName)) { // it is a system field return true; } $enumCode = $this->typeHelper->getEnumCode($className, $fieldName); if (!empty($enumCode)) { if ($options['config_is_new']) { // a new field reuses public enum return true; } $enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode); if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, 'public')) { // is immutable return true; } if ($this->typeHelper->hasOtherReferences($enumCode, $className, $fieldName)) { // an enum is reused by other fields return true; } } return false; }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $relationTableName = $this->nameGenerator->generateManyToManyJoinTableName('Oro\\Bundle\\EmailBundle\\Entity\\Email', ExtendHelper::buildAssociationName('OroCRM\\Bundle\\SalesBundle\\Entity\\B2bCustomer', ActivityScope::ASSOCIATION_KIND), 'OroCRM\\Bundle\\SalesBundle\\Entity\\B2bCustomer'); if (!$schema->hasTable($relationTableName)) { $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_b2bcustomer'); } }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Account::INTERNAL_RATING_CODE))->findAll(); /** @var \Oro\Bundle\UserBundle\Entity\User $accountOwner */ $accountOwner = $manager->getRepository('OroUserBundle:User')->findOneBy([]); foreach ($this->accounts as $accountName => $accountData) { /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $accountGroup */ $accountGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $accountData['group']); $account = new Account(); $account->setName($accountName)->setGroup($accountGroup)->setParent(null)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]); $manager->persist($account); $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $account->getName(), $account); if (isset($accountData['subsidiaries'])) { foreach ($accountData['subsidiaries'] as $subsidiaryName => $subsidiaryData) { /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $subsidiaryGroup */ $subsidiaryGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $subsidiaryData['group']); $subsidiary = new Account(); $subsidiary->setName($subsidiaryName)->setGroup($subsidiaryGroup)->setParent($account)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]); $manager->persist($subsidiary); $this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $subsidiary->getName(), $subsidiary); } } } $manager->flush(); }
/** * @param $entityClassName * @param $entityId * @return QueryBuilder */ public function getBaseAssociatedNotesQB($entityClassName, $entityId) { $ids = is_array($entityId) ? $entityId : [$entityId]; $queryBuilder = $this->createQueryBuilder('note')->innerJoin($entityClassName, 'e', 'WITH', sprintf('note.%s = e', ExtendHelper::buildAssociationName($entityClassName))); $queryBuilder->where($queryBuilder->expr()->in('e.id', $ids)); return $queryBuilder; }
/** * @param EntityConfigEvent $event */ public function updateEntityConfig(EntityConfigEvent $event) { $parentClassName = get_parent_class($event->getClassName()); if (!$parentClassName) { return; } $shortClassName = ExtendHelper::getShortClassName($event->getClassName()); if (ExtendHelper::getShortClassName($parentClassName) !== 'Extend' . $shortClassName) { return; } $config = $event->getConfigManager()->getProvider('extend')->getConfig($event->getClassName()); $hasChanges = false; if (!$config->is('is_extend')) { $config->set('is_extend', true); $hasChanges = true; } $extendClass = ExtendHelper::getExtendEntityProxyClassName($parentClassName); if (!$config->is('extend_class', $extendClass)) { $config->set('extend_class', $extendClass); $hasChanges = true; } if ($hasChanges) { $event->getConfigManager()->persist($config); } }
/** * Gets a table name for many-to-many relation * * @param string $activityTableName Activity entity table name. It is owning side of the association. * @param string $targetTableName Target entity table name. * * @return string */ public function getAssociationTableName($activityTableName, $targetTableName) { $sourceClassName = $this->extendExtension->getEntityClassByTableName($activityTableName); $targetClassName = $this->extendExtension->getEntityClassByTableName($targetTableName); $associationName = ExtendHelper::buildAssociationName($targetClassName, ActivityScope::ASSOCIATION_KIND); return $this->nameGenerator->generateManyToManyJoinTableName($sourceClassName, $associationName, $targetClassName); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /** @var UserManager $userManager */ $userManager = $this->container->get('oro_user.manager'); $admin = $userManager->findUserByEmail(LoadAdminUserData::DEFAULT_ADMIN_EMAIL); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); /** @var Store $store */ $store = $this->getReference('store'); /** @var Channel $channel */ $channel = $this->getReference('default_channel'); /** @var Integration $integration */ $integration = $this->getReference('integration'); $className = ExtendHelper::buildEnumValueClassName('mage_subscr_status'); $enumRepo = $manager->getRepository($className); foreach ($this->subscriberData as $data) { $subscriber = new NewsletterSubscriber(); $date = new \DateTime(); $date->modify('-1 day'); /** @var AbstractEnumValue $status */ $status = $enumRepo->find($data['status']); $subscriber->setEmail($data['email'])->setStatus($status)->setConfirmCode(uniqid())->setStore($store)->setOwner($admin)->setOrganization($organization)->setOriginId($data['originId'])->setChangeStatusAt($date)->setCreatedAt($date)->setUpdatedAt($date)->setChannel($integration)->setDataChannel($channel); if (!empty($data['customer'])) { /** @var Customer $customer */ $customer = $this->getReference($data['customer']); $subscriber->setCustomer($customer); } $this->setReference($data['reference'], $subscriber); $manager->persist($subscriber); } $manager->flush(); }
/** * @param ConfigInterface $entityConfig * @param string $targetEntityClassName * @param string $relationName */ protected function createOwnerRelation(ConfigInterface $entityConfig, $targetEntityClassName, $relationName) { $relationKey = ExtendHelper::buildRelationKey($entityConfig->getId()->getClassName(), $relationName, 'manyToOne', $this->ownershipMetadataProvider->getOrganizationClass()); if (!isset($entityConfig->get('relation')[$relationKey])) { $this->relationBuilder->addManyToOneRelation($entityConfig, $targetEntityClassName, $relationName, 'id', ['entity' => ['label' => 'oro.custom_entity.' . $relationName . '.label', 'description' => 'oro.custom_entity.' . $relationName . '.description'], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false], 'dataaudit' => ['auditable' => true]]); } }
/** * {@inheritdoc} */ protected function getFields(DatagridConfiguration $config) { $entityClassName = $this->entityClassResolver->getEntityClass($this->getEntityName($config)); if (!$this->configManager->hasConfig($entityClassName)) { return []; } $entityConfigProvider = $this->configManager->getProvider('entity'); $extendConfigProvider = $this->configManager->getProvider('extend'); $viewConfigProvider = $this->configManager->getProvider('view'); $datagridConfigProvider = $this->configManager->getProvider('datagrid'); $fields = []; $fieldIds = $entityConfigProvider->getIds($entityClassName); /** @var FieldConfigId $fieldId */ foreach ($fieldIds as $fieldId) { $extendConfig = $extendConfigProvider->getConfigById($fieldId); if ($extendConfig->is('owner', ExtendScope::OWNER_CUSTOM) && ExtendHelper::isFieldAccessible($extendConfig) && $datagridConfigProvider->getConfigById($fieldId)->is('is_visible')) { $viewConfig = $viewConfigProvider->getConfig($entityClassName, $fieldId->getFieldName()); $fields[] = ['id' => $fieldId, 'priority' => $viewConfig->get('priority', false, 0)]; } } ArrayUtil::sortBy($fields, true); return array_map(function ($field) { return $field['id']; }, $fields); }
/** * @param string $id * @param string $entityName * @param string $fieldName * * @return array * * @Route( * "/detailed/{id}/{entityName}/{fieldName}", * name="oro_entity_detailed", * defaults={"id"=0, "fieldName"=""} * ) * @Template */ public function detailedAction($id, $entityName, $fieldName) { $entityClass = $this->get('oro_entity.routing_helper')->resolveEntityClass($entityName); if (!class_exists($entityClass)) { throw $this->createNotFoundException(); } $this->checkAccess('VIEW', $entityClass); $entityProvider = $this->get('oro_entity_config.provider.entity'); $extendProvider = $this->get('oro_entity_config.provider.extend'); $relationConfig = $extendProvider->getConfig($entityClass, $fieldName); $relationTargetEntity = $relationConfig->get('target_entity'); if (!class_exists($relationTargetEntity)) { throw $this->createNotFoundException(); } /** @var ConfigInterface[] $fields */ $fields = $extendProvider->filter(function (ConfigInterface $config) use($relationConfig) { /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $config->getId(); return ExtendHelper::isFieldAccessible($config) && in_array($fieldConfigId->getFieldName(), (array) $relationConfig->get('target_detailed'), true); }, $relationConfig->get('target_entity')); $entity = $this->getDoctrine()->getRepository($relationTargetEntity)->find($id); if (!$entity) { return $this->createNotFoundException(); } $dynamicRow = array(); foreach ($fields as $field) { /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $field->getId(); $fieldName = $fieldConfigId->getFieldName(); $label = $entityProvider->getConfigById($fieldConfigId)->get('label') ?: $fieldName; $dynamicRow[$label] = FieldAccessor::getValue($entity, $fieldName); } return array('dynamic' => $dynamicRow, 'entity' => $entity); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('constraints' => [new Assert\NotBlank()])); $constraintsNormalizer = function (Options $options, $constraints) { /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $options['config_id']; if (!$this->typeHelper->hasEnumCode($fieldConfigId->getClassName(), $fieldConfigId->getFieldName())) { // validations of new enum $constraints[] = new Assert\Length(['max' => $this->nameGenerator->getMaxEnumCodeSize()]); $constraints[] = new Assert\Regex(['pattern' => '/^[\\w- ]*$/', 'message' => self::INVALID_NAME_MESSAGE]); $callback = function ($value, ExecutionContext $context) { if (!empty($value)) { $code = ExtendHelper::buildEnumCode($value, false); if (empty($code)) { $context->addViolation(self::INVALID_NAME_MESSAGE, ['{{ value }}' => $value]); } } }; $constraints[] = new Assert\Callback([$callback]); $constraints[] = new UniqueEnumName(['entityClassName' => $fieldConfigId->getClassName(), 'fieldName' => $fieldConfigId->getFieldName()]); } else { // validations of existing enum $constraints[] = new Assert\Length(['max' => 255]); } return $constraints; }; $resolver->setNormalizers(['constraints' => $constraintsNormalizer, 'disabled' => function (Options $options, $value) { return $this->isReadOnly($options) ? true : $value; }, 'validation_groups' => function (Options $options, $value) { return $options['disabled'] ? false : $value; }]); }
/** * Checks if the given constraint is applied or not * * @param Options $options * @param string|null $constraintName Can be: null, 'add', 'delete' * * @return bool */ protected function isDisabled($options, $constraintName = null) { /** @var ConfigIdInterface $configId */ $configId = $options['config_id']; $className = $configId->getClassName(); if (empty($className)) { return false; } $fieldName = $this->typeHelper->getFieldName($configId); if (empty($fieldName)) { return false; } $enumCode = $this->typeHelper->getEnumCode($className, $fieldName); if (!empty($enumCode)) { if ($options['config_is_new']) { // a new field reuses public enum return true; } if ($constraintName) { $enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode); if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, $constraintName)) { // is immutable return true; } } } return false; }
/** * @param ConfigInterface $sourceEntityConfig The 'extend' config of the source entity * @param string $targetEntityName * @param string $relationName * @param string $targetFieldName A field name is used to show related entity * @param array $options * @param string $fieldType The field type. By default the field type is manyToOne, * but you can specify another type if it is based on manyToOne. * In this case this type should be registered * in entity_extend.yml under underlying_types section * * @return string The relation key */ public function addManyToOneRelation(ConfigInterface $sourceEntityConfig, $targetEntityName, $relationName, $targetFieldName, $options = [], $fieldType = 'manyToOne') { $sourceEntityName = $sourceEntityConfig->getId()->getClassName(); $relationKey = ExtendHelper::buildRelationKey($sourceEntityName, $relationName, 'manyToOne', $targetEntityName); // add a relation field config if (!$this->configManager->hasConfigFieldModel($sourceEntityName, $relationName)) { $this->configManager->createConfigFieldModel($sourceEntityName, $relationName, $fieldType); $options['extend']['state'] = ExtendScope::STATE_NEW; } else { $configFieldModel = $this->configManager->getConfigFieldModel($sourceEntityName, $relationName); if ($configFieldModel->getType() !== $fieldType) { $this->configManager->changeFieldType($sourceEntityName, $relationName, $fieldType); } } $options['extend']['is_extend'] = true; $options['extend']['relation_key'] = $relationKey; $options['extend']['target_entity'] = $targetEntityName; $options['extend']['target_field'] = $targetFieldName; $this->updateFieldConfigs($sourceEntityName, $relationName, $options); // add relation to config $relations = $sourceEntityConfig->get('relation', false, []); if (!isset($relations[$relationKey])) { $relations[$relationKey] = ['assign' => false, 'field_id' => new FieldConfigId('extend', $sourceEntityName, $relationName, 'manyToOne'), 'owner' => true, 'target_entity' => $targetEntityName, 'target_field_id' => false]; $sourceEntityConfig->set('relation', $relations); $extendConfigProvider = $this->configManager->getProvider('extend'); $extendConfigProvider->persist($sourceEntityConfig); } return $relationKey; }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $defaultFieldOptions = ['multiple' => true]; $resolver->setDefaults(['enum_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions, 'operator_choices' => [self::TYPE_IN => $this->translator->trans('oro.filter.form.label_type_in'), self::TYPE_NOT_IN => $this->translator->trans('oro.filter.form.label_type_not_in')]]); $resolver->setNormalizer('class', function (Options $options, $value) { if ($value !== null) { return $value; } if (empty($options['enum_code'])) { throw new InvalidOptionsException('Either "class" or "enum_code" must option must be set.'); } $class = ExtendHelper::buildEnumValueClassName($options['enum_code']); if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) { throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue')); } return $class; }); // this normalizer allows to add/override field_options options outside $resolver->setNormalizer('field_options', function (Options $options, $value) use(&$defaultFieldOptions) { if (isset($options['class'])) { $nullValue = null; if ($options->offsetExists('null_value')) { $nullValue = $options->offsetGet('null_value'); } $value['choices'] = $this->getChoices($options['class'], $nullValue); } else { $value['choices'] = []; } return array_merge($defaultFieldOptions, $value); }); }
/** * @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 setDefaultOptions(OptionsResolverInterface $resolver) { $defaultFieldOptions = ['multiple' => true]; $resolver->setDefaults(['dictionary_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions]); $resolver->setNormalizers(['class' => function (Options $options, $value) { if ($value !== null) { return $value; } if (empty($options['dictionary_code'])) { throw new InvalidOptionsException('Either "class" or "dictionary_code" must option must be set.'); } $class = ExtendHelper::buildEnumValueClassName($options['dictionary_code']); if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) { throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue')); } return $class; }, 'field_options' => function (Options $options, $value) use(&$defaultFieldOptions) { if (isset($options['class'])) { $nullValue = null; if ($options->has('null_value')) { $nullValue = $options->get('null_value'); } $value['choices'] = $this->getChoices($options['class'], $nullValue); } else { $value['choices'] = []; } return array_merge($defaultFieldOptions, $value); }]); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /** @var AccountUser[] $accountUsers */ $accountUsers = $manager->getRepository('OroB2BCustomerBundle:AccountUser')->findAll(); $internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Customer::INTERNAL_RATING_CODE))->findAll(); $rootCustomer = null; $firstLevelCustomer = null; // create customer groups $rootGroup = $this->createCustomerGroup('Root'); $firstLevelGroup = $this->createCustomerGroup('First'); $secondLevelGroup = $this->createCustomerGroup('Second'); $manager->persist($rootGroup); $manager->persist($firstLevelGroup); $manager->persist($secondLevelGroup); // create customers foreach ($accountUsers as $index => $accountUser) { $customer = $accountUser->getCustomer(); switch ($index % 3) { case 0: $customer->setGroup($rootGroup); $rootCustomer = $customer; break; case 1: $customer->setGroup($firstLevelGroup)->setParent($rootCustomer); $firstLevelCustomer = $customer; break; case 2: $customer->setGroup($secondLevelGroup)->setParent($firstLevelCustomer); break; } $customer->setInternalRating($internalRatings[array_rand($internalRatings)]); } $manager->flush(); }
/** * @param EntityConfigEvent $event */ public function updateEntity(EntityConfigEvent $event) { $className = $event->getClassName(); $parentClassName = get_parent_class($className); if (!$parentClassName) { return; } if (ExtendHelper::isExtendEntityProxy($parentClassName)) { // When application is installed parent class will be replaced (via class_alias) $extendClass = $parentClassName; } else { // During install parent class is not replaced (via class_alias) $shortClassName = ExtendHelper::getShortClassName($className); if (ExtendHelper::getShortClassName($parentClassName) !== 'Extend' . $shortClassName) { return; } $extendClass = ExtendHelper::getExtendEntityProxyClassName($parentClassName); } $configManager = $event->getConfigManager(); $config = $configManager->getProvider('extend')->getConfig($className); $hasChanges = false; if (!$config->is('is_extend')) { $config->set('is_extend', true); $hasChanges = true; } if (!$config->is('extend_class', $extendClass)) { $config->set('extend_class', $extendClass); $hasChanges = true; } if ($hasChanges) { $configManager->persist($config); } }
/** * Checks if the entity can has notes * * @param object $entity * @return bool */ public function isNoteAssociationEnabled($entity) { if (null === $entity || !is_object($entity)) { return false; } $className = ClassUtils::getClass($entity); return $this->noteConfigProvider->hasConfig($className) && $this->noteConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Note::ENTITY_NAME, ExtendHelper::buildAssociationName($className)); }
/** * 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)); }
/** * {@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'))); }
/** * Checks if the entity can have comments * * @param object|null $entity * * @return bool */ public function isApplicable($entity) { if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) { return false; } $className = ClassUtils::getClass($entity); return $this->commentConfigProvider->hasConfig($className) && $this->commentConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Comment::ENTITY_NAME, ExtendHelper::buildAssociationName($className)); }
/** * Checks if the entity can has notes * * @param object $entity * @return bool */ public function isAttachmentAssociationEnabled($entity) { if (null === $entity || !is_object($entity)) { return false; } $className = ClassUtils::getClass($entity); return $this->attachmentConfigProvider->hasConfig($className) && $this->attachmentConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName($className)); }
/** * 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)); }
public function testCreateEnumValueWithoutId() { $result = $this->repo->createEnumValue('Test Value 1', 1, true); $this->assertInstanceOf(self::ENUM_VALUE_CLASS_NAME, $result); $this->assertEquals(ExtendHelper::buildEnumValueId('Test Value 1'), $result->getId()); $this->assertEquals('Test Value 1', $result->getName()); $this->assertEquals(1, $result->getPriority()); $this->assertTrue($result->isDefault()); }
public function testIsAttachmentAssociationEnabled() { $config = new Config(new EntityConfigId('attachment', 'stdClass')); $config->set('enabled', true); $this->attachmentConfigProvider->expects($this->once())->method('hasConfig')->with('stdClass')->will($this->returnValue(true)); $this->attachmentConfigProvider->expects($this->once())->method('getConfig')->with('stdClass')->will($this->returnValue($config)); $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName('stdClass'))->will($this->returnValue(true)); $this->assertTrue($this->filter->isAttachmentAssociationEnabled(new \stdClass())); }
public function testIsNoteAssociationEnabled() { $config = new Config(new EntityConfigId('note', static::TEST_ENTITY_REFERENCE)); $config->set('enabled', true); $this->noteConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true)); $this->noteConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config)); $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Note::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true)); $this->assertTrue($this->filter->isNoteAssociationEnabled(new TestEntity(1))); }
public function testGenerate() { $schema = ['relationData' => [['field_id' => new FieldConfigId('extend', 'Test\\Entity', ExtendHelper::buildAssociationName('Test\\TargetEntity1', ActivityScope::ASSOCIATION_KIND), 'manyToMany'), 'target_entity' => 'Test\\TargetEntity1'], ['field_id' => new FieldConfigId('extend', 'Test\\Entity', ExtendHelper::buildAssociationName('Test\\TargetEntity2', ActivityScope::ASSOCIATION_KIND), 'manyToMany'), 'target_entity' => 'Test\\TargetEntity2'], ['field_id' => new FieldConfigId('extend', 'Test\\Entity', ExtendHelper::buildAssociationName('Test\\TargetEntity3', ActivityScope::ASSOCIATION_KIND), 'manyToOne'), 'target_entity' => 'Test\\TargetEntity3'], ['field_id' => new FieldConfigId('extend', 'Test\\Entity', 'testField', 'manyToMany'), 'target_entity' => 'Test\\TargetEntity4']]]; $class = PhpClass::create('Test\\Entity'); $this->extension->generate($schema, $class); $strategy = new DefaultGeneratorStrategy(); $classBody = $strategy->generate($class); $expectedBody = file_get_contents(__DIR__ . '/Fixtures/generationResult.txt'); $this->assertEquals(trim($expectedBody), $classBody); }