/** * {@inheritdoc} */ public function getDirection($activity, $target) { //check if target is entity created from admin part if (!$target instanceof EmailHolderInterface) { $metadata = $this->doctrineHelper->getEntityMetadata($target); $columns = $metadata->getColumnNames(); $className = get_class($target); foreach ($columns as $column) { //check only columns with 'contact_information' if ($this->isEmailType($className, $column)) { $getMethodName = "get" . Inflector::classify($column); /** @var $activity Email */ if ($activity->getFromEmailAddress()->getEmail() === $target->{$getMethodName}()) { return DirectionProviderInterface::DIRECTION_OUTGOING; } else { foreach ($activity->getTo() as $recipient) { if ($recipient->getEmailAddress()->getEmail() === $target->{$getMethodName}()) { return DirectionProviderInterface::DIRECTION_INCOMING; } } } } } return DirectionProviderInterface::DIRECTION_UNKNOWN; } /** @var $activity Email */ /** @var $target EmailHolderInterface */ if ($activity->getFromEmailAddress()->getEmail() === $target->getEmail()) { return DirectionProviderInterface::DIRECTION_OUTGOING; } return DirectionProviderInterface::DIRECTION_INCOMING; }
/** * @param DatagridInterface $dataGrid * @return string */ protected function getEntityName(DatagridInterface $dataGrid) { /** @var OrmDatasource $dataSource */ $dataSource = $dataGrid->getDatasource(); $queryBuilder = $dataSource->getQueryBuilder(); $entityName = $queryBuilder->getRootEntities()[0]; return $this->doctrineHelper->getEntityMetadata($entityName)->getName(); }
/** * Get entity contact information fields. * * @param string|object $entity * @return array */ public function getEntityContactInformationColumns($entity) { $metadata = $this->doctrineHelper->getEntityMetadata($entity); $columns = $metadata->getColumnNames(); $contactInformationColumns = array(); foreach ($columns as $column) { if ($type = $this->getContactInformationFieldType($entity, $column)) { $contactInformationColumns[$column] = $type; } } return array_merge($contactInformationColumns, $this->getEntityLevelContactInfoColumns($entity)); }
/** * @return ClassMetadata */ protected function getMetadata() { if (!$this->metadata) { $this->metadata = $this->doctrineHelper->getEntityMetadata(self::CALENDAR_PROPERTY_CLASS); } return $this->metadata; }
public function testGetEntityMetadataNotManageableEntity() { $class = 'ItemStubProxy'; $this->setExpectedException('Oro\\Bundle\\EntityBundle\\Exception\\NotManageableEntityException', sprintf('Entity class "%s" is not manageable', $class)); $this->registry->expects($this->once())->method('getManagerForClass')->with($class)->will($this->returnValue(null)); $this->doctrineHelper->getEntityMetadata($class); }
/** * @param FormEvent $event */ public function postSubmit(FormEvent $event) { $form = $event->getForm(); $added = $form->get('added')->getData(); $removed = $form->get('removed')->getData(); $parentData = $form->getParent()->getData(); /** @var ClassMetadata $parentMetadata */ $parentMetadata = $this->doctrineHelper->getEntityMetadata(ClassUtils::getClass($parentData)); /** @var Collection $collection */ $collection = $form->getData(); foreach ($added as $relation) { $this->processRelation($parentMetadata, $relation, $parentData); $collection->add($relation); } foreach ($removed as $relation) { $this->processRelation($parentMetadata, $relation, null); $collection->removeElement($relation); } }
/** * @param FormInterface $form * @param array $categories */ protected function addRFMTypes(FormInterface $form, array $categories) { foreach (RFMMetricCategory::$types as $type) { $typeCategories = array_filter($categories, function (RFMMetricCategory $category) use($type) { return $category->getCategoryType() === $type; }); $collection = new PersistentCollection($this->doctrineHelper->getEntityManager($this->rfmCategoryClass), $this->doctrineHelper->getEntityMetadata($this->rfmCategoryClass), new ArrayCollection($typeCategories)); $collection->takeSnapshot(); $constraint = new CategoriesConstraint(); $constraint->setType($type); $form->add($type, RFMCategorySettingsType::NAME, [RFMCategorySettingsType::TYPE_OPTION => $type, 'label' => sprintf('orocrm.analytics.form.%s.label', $type), 'tooltip' => sprintf('orocrm.analytics.%s.tooltip', $type), 'mapped' => false, 'required' => false, 'error_bubbling' => false, 'is_increasing' => $type === RFMMetricCategory::TYPE_RECENCY, 'constraints' => [$constraint], 'data' => $collection]); } }
/** * @param object $entity * @param array $data */ protected function fillEntityData($entity, array $data = []) { if (!$data) { return; } if (!$this->propertyAccessor) { $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); } $metadata = $this->doctrineHelper->getEntityMetadata($entity); foreach ($data as $property => $value) { try { if ($metadata->hasAssociation($property)) { $value = $this->doctrineHelper->getEntityReference($metadata->getAssociationTargetClass($property), $value); } $this->propertyAccessor->setValue($entity, $property, $value); } catch (NoSuchPropertyException $e) { } } }
/** * This method should be used for fast changing data in 'relation' tables, because * it uses Plain SQL for updating data in tables. * Currently there is no another way for updating big amount of data: with Doctrine way * it takes a lot of time(because of big amount of operations with objects, event listeners etc.); * with DQL currently it impossible to build query, because DQL works only with entities, but * 'relation' tables are not entities. For example: there is 'relation' * table 'oro_rel_c3990ba6b28b6f38c460bc' and it has activitylist_id and account_id columns, * in fact to solve initial issue with big amount of data we need update only account_id column * with new values. * * @param array $activityIds * @param string $targetClass * @param integer $oldTargetId * @param integer $newTargetId * @param null|string $activityClass * * @return $this * * @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\ORM\Mapping\MappingException */ public function replaceActivityTargetWithPlainQuery(array $activityIds, $targetClass, $oldTargetId, $newTargetId, $activityClass = null) { if (is_null($activityClass)) { $associationName = $this->getActivityListAssociationName($targetClass); $entityClass = ActivityList::ENTITY_NAME; } else { $associationName = $this->getActivityAssociationName($targetClass); $entityClass = $activityClass; } $entityMetadata = $this->doctrineHelper->getEntityMetadata($entityClass); if (!empty($activityIds) && $entityMetadata->hasAssociation($associationName)) { $association = $entityMetadata->getAssociationMapping($associationName); $tableName = $association['joinTable']['name']; $activityField = current(array_keys($association['relationToSourceKeyColumns'])); $targetField = current(array_keys($association['relationToTargetKeyColumns'])); $where = "WHERE {$targetField} = :sourceEntityId AND {$activityField} IN(" . implode(',', $activityIds) . ")"; $dbConnection = $this->doctrineHelper->getEntityManager(ActivityList::ENTITY_NAME)->getConnection()->prepare("UPDATE {$tableName} SET {$targetField} = :masterEntityId {$where}"); $dbConnection->bindValue('masterEntityId', $newTargetId); $dbConnection->bindValue('sourceEntityId', $oldTargetId); $dbConnection->execute(); } return $this; }
/** * @param string $className * * @return array */ protected function getSupportedFields($className) { $classMetadata = $this->doctrineHelper->getEntityMetadata($className); return $classMetadata->fieldNames; }
/** * @param OrmDatasource $dataSource * @return string */ protected function getEntityName(OrmDatasource $dataSource) { $queryBuilder = $dataSource->getQueryBuilder(); $entityName = $queryBuilder->getRootEntities()[0]; return $this->doctrineHelper->getEntityMetadata($entityName)->getName(); }
/** * @expectedException \Oro\Bundle\EntityBundle\Exception\NotManageableEntityException * @expectedExceptionMessage Entity class "ItemStubProxy" is not manageable */ public function testGetEntityMetadataNotManageableEntity() { $class = 'ItemStubProxy'; $this->registry->expects($this->once())->method('getManagerForClass')->with($class)->will($this->returnValue(null)); $this->doctrineHelper->getEntityMetadata($class); }
public function testGetEntityMetadataNotManageableEntityWithoutThrowException() { $class = 'ItemStub'; $this->registry->expects($this->once())->method('getManagerForClass')->with($class)->will($this->returnValue(null)); $this->assertNull($this->doctrineHelper->getEntityMetadata($class, false)); }