Exemplo n.º 1
0
 public function testSettersAndGetters()
 {
     $this->assertNull($this->entity->getId());
     $this->assertNull($this->entity->getName());
     $this->assertNull($this->entity->getDefinition());
     $this->assertNull($this->entity->getDescription());
     $this->assertNull($this->entity->getType());
     $this->assertNull($this->entity->getEntity());
     $this->assertNull($this->entity->getOwner());
     $this->assertNull($this->entity->getCreatedAt());
     $this->assertNull($this->entity->getUpdatedAt());
     $this->assertNull($this->entity->getLastRun());
     $this->assertNull($this->entity->getOrganization());
     $testData = uniqid('name');
     $this->entity->setName($testData);
     $this->assertEquals($testData, $this->entity->getName());
     $testData = uniqid('definition');
     $this->entity->setDefinition($testData);
     $this->assertEquals($testData, $this->entity->getDefinition());
     $testData = uniqid('description');
     $this->entity->setDescription($testData);
     $this->assertEquals($testData, $this->entity->getDescription());
     $testData = $this->getMock('Oro\\Bundle\\SegmentBundle\\Entity\\SegmentType', [], ['testTypeName']);
     $this->entity->setType($testData);
     $this->assertSame($testData, $this->entity->getType());
     $testData = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit');
     $this->entity->setOwner($testData);
     $this->assertSame($testData, $this->entity->getOwner());
     $testData = uniqid('entity');
     $this->entity->setEntity($testData);
     $this->assertEquals($testData, $this->entity->getEntity());
     $testData = new \DateTime();
     $this->entity->setCreatedAt($testData);
     $this->assertSame($testData, $this->entity->getCreatedAt());
     $testData = new \DateTime();
     $this->entity->setUpdatedAt($testData);
     $this->assertSame($testData, $this->entity->getUpdatedAt());
     $testData = new \DateTime();
     $this->entity->setLastRun($testData);
     $this->assertSame($testData, $this->entity->getLastRun());
     $testData = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization');
     $this->entity->setOrganization($testData);
     $this->assertSame($testData, $this->entity->getOrganization());
 }
 /**
  * {@inheritdoc}
  */
 public function getQueryBuilder(Segment $segment)
 {
     $converter = new SegmentQueryConverter($this->manager, $this->virtualFieldProvider, $this->doctrine, $this->restrictionBuilder);
     if ($this->virtualRelationProvider) {
         $converter->setVirtualRelationProvider($this->virtualRelationProvider);
     }
     /** @var EntityManager  $em */
     $em = $this->doctrine->getManagerForClass($segment->getEntity());
     $qb = $converter->convert(new RestrictionSegmentProxy($segment, $em));
     return $qb;
 }
Exemplo n.º 3
0
 /**
  * Limit segment data by segment's organization
  *
  * @param Segment      $segment
  * @param QueryBuilder $qb
  */
 protected function applyOrganizationLimit(Segment $segment, QueryBuilder $qb)
 {
     $organizationField = $this->ownershipMetadataProvider->getMetadata($segment->getEntity())->getGlobalOwnerFieldName();
     if ($organizationField) {
         $qb->andWhere(sprintf('%s.%s = %s', $qb->getRootAliases()[0], $organizationField, $segment->getOrganization()->getId()));
     }
 }
 /**
  * {inheritdoc}
  */
 public function build(Segment $segment)
 {
     $converter = new SegmentQueryConverter($this->manager, $this->virtualFieldProvider, $this->doctrine, $this->restrictionBuilder);
     $qb = $converter->convert(new RestrictionSegmentProxy($segment, $this->doctrine->getManagerForClass($segment->getEntity())));
     return $qb->getQuery();
 }
Exemplo n.º 5
0
 /**
  * @param QueryBuilder $queryBuilder
  * @param Segment      $segment
  *
  * @return string
  */
 protected function getIdentityFieldWithAlias(QueryBuilder $queryBuilder, Segment $segment)
 {
     $tableAliases = $queryBuilder->getRootAliases();
     $em = $queryBuilder->getEntityManager();
     $entityMetadata = $em->getClassMetadata($segment->getEntity());
     $idField = $entityMetadata->getSingleIdentifierFieldName();
     if ($this->isDynamic($segment)) {
         return $tableAliases[0] . '.' . $idField;
     }
     $idFieldType = $entityMetadata->getTypeOfField($idField);
     $fieldToSelect = SegmentSnapshot::ENTITY_REF_FIELD;
     if ($idFieldType == 'integer') {
         $fieldToSelect = SegmentSnapshot::ENTITY_REF_INTEGER_FIELD;
     }
     return $tableAliases[0] . '.' . $fieldToSelect;
 }
 /**
  * Get SELECT query builder for retrieving entity identifiers from snapshot
  *
  * @param Segment $segment
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function getIdentifiersSelectQueryBuilder(Segment $segment)
 {
     $entityMetadata = $this->getEntityManager()->getClassMetadata($segment->getEntity());
     $idField = $entityMetadata->getSingleIdentifierFieldName();
     $idFieldType = $entityMetadata->getTypeOfField($idField);
     if ($idFieldType == 'integer') {
         $fieldToSelect = 'CAST(snp.entityId as int)';
     } else {
         $fieldToSelect = 'snp.entityId';
     }
     $qb = $this->createQueryBuilder('snp')->select($fieldToSelect)->where('snp.segment = :segment')->setParameter('segment', $segment);
     return $qb;
 }
 /**
  * Get SELECT query builder for retrieving entity identifiers from snapshot
  *
  * @param Segment $segment
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function getIdentifiersSelectQueryBuilder(Segment $segment)
 {
     $entityMetadata = $this->getEntityManager()->getClassMetadata($segment->getEntity());
     $idField = $entityMetadata->getSingleIdentifierFieldName();
     $idFieldType = $entityMetadata->getTypeOfField($idField);
     $fieldToSelect = SegmentSnapshot::ENTITY_REF_FIELD;
     if ($idFieldType == 'integer') {
         $fieldToSelect = SegmentSnapshot::ENTITY_REF_INTEGER_FIELD;
     }
     $fieldToSelect = sprintf('snp.%s', $fieldToSelect);
     $qb = $this->createQueryBuilder('snp')->select($fieldToSelect)->where('snp.segment = :segment')->setParameter('segment', $segment);
     return $qb;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getEntity()
 {
     return $this->segment->getEntity();
 }