Beispiel #1
0
 /**
  * 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);
 }
 /**
  * @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);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * @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;
 }
Beispiel #4
0
 /**
  * {@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');
     }
 }
 /**
  * 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));
 }
 /**
  * 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 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));
 }
 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 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 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);
 }
 public function testIsApplicable()
 {
     $config = new Config(new EntityConfigId('comment', static::TEST_ENTITY_REFERENCE));
     $config->set('enabled', true);
     $this->securityFacade->expects($this->once())->method('isGranted')->with('oro_comment_view')->willReturn(true);
     $this->commentConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
     $this->commentConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Comment::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true));
     $this->assertTrue($this->filter->isApplicable(new TestEntity()));
 }
 /**
  * Adds the association between the target table and the visit table
  *
  * @param Schema $schema
  * @param string $targetTableName  Target entity table name
  * @param string $targetColumnName A column name is used to show related entity
  */
 public function addIdentifierAssociation(Schema $schema, $targetTableName, $targetColumnName = null)
 {
     $visitTable = $schema->getTable(self::VISIT_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     if (empty($targetColumnName)) {
         $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
         $targetColumnName = array_shift($primaryKeyColumns);
     }
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), self::ASSOCIATION_KIND);
     $this->extendExtension->addManyToOneRelation($schema, $visitTable, $associationName, $targetTable, $targetColumnName);
 }
Beispiel #15
0
 /**
  * @param string   $entityClassName
  * @param mixed    $entityId
  * @param int|null $page
  * @param int|null $limit
  *
  * @return QueryBuilder
  */
 public function getAssociatedNotesQueryBuilder($entityClassName, $entityId, $page = null, $limit = null)
 {
     $qb = $this->createQueryBuilder('note')->select('partial note.{id, message, owner, createdAt, updatedBy, updatedAt}, c, u')->innerJoin($entityClassName, 'e', 'WITH', sprintf('note.%s = e', ExtendHelper::buildAssociationName($entityClassName)))->leftJoin('note.owner', 'c')->leftJoin('note.updatedBy', 'u')->where('e.id = :entity_id')->setParameter('entity_id', $entityId);
     if (null !== $page) {
         $qb->setFirstResult($this->getOffset($page) * $limit);
     }
     if (null !== $limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
 /**
  * @param EntityManager $em
  * @param object        $target
  * @param integer       $skipId
  * @param string        $direction
  *
  * @return Call
  */
 protected function getLastActivity(EntityManager $em, $target, $skipId, $direction = null)
 {
     $qb = $em->getRepository('OroCRM\\Bundle\\CallBundle\\Entity\\Call')->createQueryBuilder('call')->select('call')->innerJoin(sprintf('call.%s', ExtendHelper::buildAssociationName(ClassUtils::getClass($target), ActivityScope::ASSOCIATION_KIND)), 'target')->andWhere('target = :target')->orderBy('call.callDateTime', 'DESC')->setMaxResults(1)->setParameter('target', $target->getId());
     if ($skipId) {
         $qb->andWhere('call.id <> :skipId')->setParameter('skipId', $skipId);
     }
     if ($direction) {
         $qb->join('call.direction', 'direction')->andWhere('direction.name = :direction')->setParameter('direction', $direction);
     }
     return $qb->getQuery()->getOneOrNullResult();
 }
 /**
  * {@inheritdoc}
  */
 public function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     if ($metadata->name !== 'Oro\\Bundle\\AttachmentBundle\\Entity\\Attachment') {
         return false;
     }
     $mapping = $metadata->getAssociationMapping($associationName);
     if (!$mapping['isOwningSide'] || !($mapping['type'] & ClassMetadata::MANY_TO_ONE)) {
         return false;
     }
     return $associationName === ExtendHelper::buildAssociationName($mapping['targetEntity']);
 }
 /**
  * {@inheritdoc}
  */
 public function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     if ($metadata->name !== 'Oro\\Bundle\\TrackingBundle\\Entity\\TrackingVisit') {
         return false;
     }
     $mapping = $metadata->getAssociationMapping($associationName);
     if (!$mapping['isOwningSide'] || !($mapping['type'] & ClassMetadata::MANY_TO_ONE)) {
         return false;
     }
     $identifierEventAssociationName = ExtendHelper::buildAssociationName($mapping['targetEntity'], IdentifierEventExtension::ASSOCIATION_KIND);
     return $associationName === $identifierEventAssociationName;
 }
 /**
  * Adds the association between the given table and the activity list table
  *
  * @param Schema $schema
  * @param string $targetTableName Target entity table name
  */
 public function addActivityListAssociation(Schema $schema, $targetTableName)
 {
     $targetTable = $schema->getTable($targetTableName);
     // Column names are used to show a title of target entity
     $targetTitleColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show detailed info about target entity
     $targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show target entity in a grid
     $targetGridColumnNames = $targetTable->getPrimaryKeyColumns();
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND);
     $this->extendExtension->addManyToManyRelation($schema, $schema->getTable('oro_activity_list'), $associationName, $targetTable, $targetTitleColumnNames, $targetDetailedColumnNames, $targetGridColumnNames, ['extend' => ['without_default' => true]]);
 }
Beispiel #20
0
 /**
  * @param object $entity
  *
  * @return Attachment[]
  */
 public function getEntityAttachments($entity)
 {
     $entityClass = ClassUtils::getClass($entity);
     if ($this->attachmentAssociationHelper->isAttachmentAssociationEnabled($entityClass)) {
         $fieldName = ExtendHelper::buildAssociationName($entityClass);
         $repo = $this->em->getRepository('OroAttachmentBundle:Attachment');
         $qb = $repo->createQueryBuilder('a');
         $qb->leftJoin('a.' . $fieldName, 'entity')->where('entity.id = :entityId')->setParameter('entityId', $entity->getId());
         return $qb->getQuery()->getResult();
     }
     return [];
 }
 /**
  * @param string $sourceEntityClass
  * @param string $targetEntityClass
  * @param string $associationKind
  */
 public function createManyToOneAssociation($sourceEntityClass, $targetEntityClass, $associationKind)
 {
     $relationName = ExtendHelper::buildAssociationName($targetEntityClass, $associationKind);
     $entityConfigProvider = $this->configManager->getProvider('entity');
     $targetEntityConfig = $entityConfigProvider->getConfig($targetEntityClass);
     $label = $targetEntityConfig->get('label', false, ConfigHelper::getTranslationKey('entity', 'label', $targetEntityClass, $relationName));
     $description = ConfigHelper::getTranslationKey('entity', 'description', $targetEntityClass, $relationName);
     $targetEntityPrimaryKeyColumns = $this->getPrimaryKeyColumnNames($targetEntityClass);
     $targetFieldName = array_shift($targetEntityPrimaryKeyColumns);
     // add relation to owning entity
     $this->relationBuilder->addManyToOneRelation($this->configManager->getProvider('extend')->getConfig($sourceEntityClass), $targetEntityClass, $relationName, $targetFieldName, ['entity' => ['label' => $label, 'description' => $description], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false]]);
 }
Beispiel #22
0
 /**
  * Adds the association between the target table and the note table
  *
  * @param Schema $schema
  * @param string $targetTableName  Target entity table name
  * @param string $targetColumnName A column name is used to show related entity
  */
 public function addNoteAssociation(Schema $schema, $targetTableName, $targetColumnName = null)
 {
     $noteTable = $schema->getTable(self::NOTE_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     if (empty($targetColumnName)) {
         $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
         $targetColumnName = array_shift($primaryKeyColumns);
     }
     $options = new OroOptions();
     $options->set('note', 'enabled', true);
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));
     $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName);
 }
 public function testIsNoteAssociationEnabledForEnabledButNotAccessibleAssociation()
 {
     $entityClass = 'Test\\Entity';
     $config = new Config(new EntityConfigId('note', $entityClass));
     $config->set('enabled', true);
     $associationName = ExtendHelper::buildAssociationName($entityClass);
     $associationConfig = new Config(new FieldConfigId('extend', NoteAssociationHelper::NOTE_ENTITY, $associationName));
     $associationConfig->set('is_extend', true);
     $associationConfig->set('state', ExtendScope::STATE_NEW);
     $this->configManager->expects($this->exactly(2))->method('hasConfig')->willReturnMap([[$entityClass, null, true], [NoteAssociationHelper::NOTE_ENTITY, $associationName, true]]);
     $this->configManager->expects($this->once())->method('getEntityConfig')->with('note', $entityClass)->willReturn($config);
     $this->configManager->expects($this->once())->method('getFieldConfig')->with('extend', NoteAssociationHelper::NOTE_ENTITY, $associationName)->willReturn($associationConfig);
     $this->assertFalse($this->noteAssociationHelper->isNoteAssociationEnabled($entityClass));
 }
 /**
  * Adds the association between the target table and the attachment table
  *
  * @param Schema   $schema
  * @param string   $targetTableName  Target entity table name
  * @param string[] $allowedMimeTypes The list of allowed MIME types
  * @param int      $maxFileSize      Max allowed file size in megabytes
  */
 public function addAttachmentAssociation(Schema $schema, $targetTableName, array $allowedMimeTypes = [], $maxFileSize = 1)
 {
     $noteTable = $schema->getTable(self::ATTACHMENT_ASSOCIATION_TABLE_NAME);
     $targetTable = $schema->getTable($targetTableName);
     $primaryKeyColumns = $targetTable->getPrimaryKeyColumns();
     $targetColumnName = array_shift($primaryKeyColumns);
     $options = new OroOptions();
     $options->set('attachment', 'enabled', true);
     $options->set('attachment', 'maxsize', $maxFileSize);
     $options->set('attachment', 'mimetypes', implode("\n", $allowedMimeTypes));
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName));
     $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName);
 }
Beispiel #25
0
 /**
  * @param string $sourceEntityClass
  * @param string $targetEntityClass
  * @param string $associationKind
  */
 public function createManyToOneAssociation($sourceEntityClass, $targetEntityClass, $associationKind)
 {
     $relationName = ExtendHelper::buildAssociationName($targetEntityClass, $associationKind);
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $targetEntityPrimaryKeyColumns = $this->getPrimaryKeyColumnNames($targetEntityClass);
     $targetFieldName = reset($targetEntityPrimaryKeyColumns);
     // add relation to owning entity
     $this->relationBuilder->addManyToOneRelation($extendConfigProvider->getConfig($sourceEntityClass), $targetEntityClass, $relationName, $targetFieldName);
     // update attributes for new association
     $fieldConfig = $extendConfigProvider->getConfig($sourceEntityClass, $relationName);
     if ($fieldConfig->is('state', ExtendScope::STATE_NEW)) {
         $targetEntityConfig = $this->configManager->getProvider('entity')->getConfig($targetEntityClass);
         $this->relationBuilder->updateFieldConfigs($sourceEntityClass, $relationName, ['entity' => ['label' => $this->getAssociationLabel('label', $sourceEntityClass, $relationName, $targetEntityConfig), 'description' => $this->getAssociationLabel('description', $sourceEntityClass, $relationName, $targetEntityConfig)], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false]]);
     }
 }
 /**
  * @param EntityManager $em
  * @param object        $target
  * @param integer       $skipId
  * @param string        $direction
  *
  * @return Email
  */
 protected function getLastActivity(EntityManager $em, $target, $skipId = null, $direction = null)
 {
     $qb = $em->getRepository('Oro\\Bundle\\EmailBundle\\Entity\\Email')->createQueryBuilder('email')->select('email')->innerJoin(sprintf('email.%s', ExtendHelper::buildAssociationName(ClassUtils::getClass($target), ActivityScope::ASSOCIATION_KIND)), 'target')->andWhere('target = :target')->orderBy('email.sentAt', 'DESC')->setMaxResults(1)->setParameter('target', $target);
     if ($skipId) {
         $qb->andWhere('email.id <> :skipId')->setParameter('skipId', $skipId);
     }
     if ($direction) {
         $operator = '!=';
         if ($direction === DirectionProviderInterface::DIRECTION_OUTGOING) {
             $operator = '=';
         }
         $qb->join('email.fromEmailAddress', 'fromEmailAddress')->andWhere('fromEmailAddress.email ' . $operator . ':email')->setParameter('email', $target->getEmail());
     }
     return $qb->getQuery()->getOneOrNullResult();
 }
 /**
  * {@inheritdoc}
  */
 public function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     if (!$this->configManager->hasConfig($metadata->name, $associationName)) {
         return false;
     }
     $groups = $this->configManager->getEntityConfig('grouping', $metadata->name)->get('groups');
     if (empty($groups) || !in_array(ActivityScope::GROUP_ACTIVITY, $groups, true)) {
         return false;
     }
     $mapping = $metadata->getAssociationMapping($associationName);
     if (!$mapping['isOwningSide'] || !($mapping['type'] & ClassMetadata::MANY_TO_MANY)) {
         return false;
     }
     $activityAssociationName = ExtendHelper::buildAssociationName($mapping['targetEntity'], ActivityScope::ASSOCIATION_KIND);
     return $associationName === $activityAssociationName;
 }
Beispiel #28
0
 /**
  * Adds the association between the given table and the table contains activity records
  *
  * The activity entity must be included in 'activity' group ('groups' attribute of 'grouping' scope)
  *
  * @param Schema $schema
  * @param string $activityTableName Activity entity table name. It is owning side of the association
  * @param string $targetTableName   Target entity table name
  * @param bool   $immutable         Set TRUE to prohibit disabling the activity association from UI
  */
 public function addActivityAssociation(Schema $schema, $activityTableName, $targetTableName, $immutable = false)
 {
     $targetTable = $schema->getTable($targetTableName);
     // Column names are used to show a title of target entity
     $targetTitleColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show detailed info about target entity
     $targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns();
     // Column names are used to show target entity in a grid
     $targetGridColumnNames = $targetTable->getPrimaryKeyColumns();
     $activityClassName = $this->extendExtension->getEntityClassByTableName($activityTableName);
     $options = new OroOptions();
     $options->append('activity', 'activities', $activityClassName);
     if ($immutable) {
         $options->append('activity', 'immutable', $activityClassName);
     }
     $targetTable->addOption(OroOptions::KEY, $options);
     $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), ActivityScope::ASSOCIATION_KIND);
     $this->extendExtension->addManyToManyRelation($schema, $activityTableName, $associationName, $targetTable, $targetTitleColumnNames, $targetDetailedColumnNames, $targetGridColumnNames, ['extend' => ['without_default' => true]]);
 }
Beispiel #29
0
 protected function processRequest(Request $request)
 {
     /** @var NoteSoap $note */
     $note = $request->request->get('note');
     /** @var EntityIdSoap $association */
     $association = $note['entityId'];
     if ($association && $association['id']) {
         /** @var ConfigProvider $noteProvider */
         $noteProvider = $this->configManager->getProvider('note');
         /** @var ConfigProvider $extendProvider */
         $extendProvider = $this->configManager->getProvider('extend');
         $fieldName = ExtendHelper::buildAssociationName($association['entity']);
         if ($noteProvider->hasConfig(Note::ENTITY_NAME, $fieldName) && $extendProvider->getConfig(Note::ENTITY_NAME, $fieldName)->is('state', ExtendScope::STATE_ACTIVE)) {
             $note[$fieldName] = $association['id'];
             unset($note['entityId']);
             $request->request->set('note', $note);
         } else {
             throw new \SoapFault('NOT_FOUND', sprintf('Notes do not enabled or schema not updated for given entity "%s".', $association['entity']));
         }
     } else {
         throw new \SoapFault('NOT_FOUND', 'Associated entity OR it\'s instance Id not found.');
     }
     return $request;
 }
Beispiel #30
0
 /**
  * @param EntityManager $em
  * @param array $data
  * @param string $entityIdField
  *
  * @return QueryBuilder
  */
 protected function createActivityQueryBuilder(EntityManager $em, array $data, $entityIdField)
 {
     $joinField = sprintf('%s.%s', $this->activityListAlias, ExtendHelper::buildAssociationName($data['entityClassName'], ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND));
     $activityListRepository = $em->getRepository('OroActivityListBundle:ActivityList');
     $activityQb = $activityListRepository->createQueryBuilder($this->activityListAlias)->select('1')->setMaxResults(1);
     $availableActivityAssociations = $this->activityManager->getActivityAssociations($data['entityClassName']);
     if (!$availableActivityAssociations && !$activityListRepository->getRecordsCountForTargetClass($data['entityClassName'])) {
         $activityQb->andWhere('1 = 0');
         return $activityQb;
     }
     $activityQb->join($joinField, $this->activityAlias)->andWhere(sprintf('%s.id = %s.%s', $this->activityAlias, $this->getEntityAlias(), $entityIdField));
     $entityField = $this->getField();
     $dateRangeField = strpos($entityField, '$') === 0 ? substr($entityField, 1) : null;
     if ($dateRangeField) {
         $data['dateRange'] = $data['filter']['data'];
         unset($data['filter']);
     }
     $this->activityListFilterHelper->addFiltersToQuery($activityQb, $data, $dateRangeField, $this->activityListAlias);
     if (isset($data['filter'])) {
         $activityDs = new OrmFilterDatasourceAdapter($activityQb);
         $expr = $activityDs->expr()->exists($this->createRelatedActivityDql($activityDs, $data));
         $this->applyFilterToClause($activityDs, $expr);
     }
     return $activityQb;
 }