本文整理汇总了PHP中Oro\Bundle\EntityBundle\ORM\DoctrineHelper::getEntityManager方法的典型用法代码示例。如果您正苦于以下问题:PHP DoctrineHelper::getEntityManager方法的具体用法?PHP DoctrineHelper::getEntityManager怎么用?PHP DoctrineHelper::getEntityManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityBundle\ORM\DoctrineHelper
的用法示例。
在下文中一共展示了DoctrineHelper::getEntityManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStatisticsRecord
/**
* @param EmailCampaign $emailCampaign
* @param object $entity
* @return EmailCampaignStatistics
*/
public function getStatisticsRecord(EmailCampaign $emailCampaign, $entity)
{
$marketingList = $emailCampaign->getMarketingList();
$entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity);
/**
* Cache was added because there is a case:
* - 2 email campaigns linked to one marketing list
* - statistic can created using batches (marketing list item connector will be used)
* and flush will be run once per N records creation
* in this case same Marketing list entity will be received twice for one marketing list
* and new MarketingListItem for same $marketingList and $entityId will be persisted twice.
*
* Marketing list name used as key for cache because Id can be empty and name is unique
*
*/
if (empty($this->marketingListItemCache[$marketingList->getName()][$entityId])) {
// Mark marketing list item as contacted
$this->marketingListItemCache[$marketingList->getName()][$entityId] = $this->marketingListItemConnector->getMarketingListItem($marketingList, $entityId);
}
/** @var MarketingListItem $marketingListItem */
$marketingListItem = $this->marketingListItemCache[$marketingList->getName()][$entityId];
$manager = $this->doctrineHelper->getEntityManager($this->entityName);
$statisticsRecord = null;
if ($marketingListItem->getId() !== null) {
$statisticsRecord = $manager->getRepository($this->entityName)->findOneBy(['emailCampaign' => $emailCampaign, 'marketingListItem' => $marketingListItem]);
}
if (!$statisticsRecord) {
$statisticsRecord = new EmailCampaignStatistics();
$statisticsRecord->setEmailCampaign($emailCampaign)->setMarketingListItem($marketingListItem)->setOwner($emailCampaign->getOwner())->setOrganization($emailCampaign->getOrganization());
$manager->persist($statisticsRecord);
}
return $statisticsRecord;
}
示例2: batchUpdate
/**
* {@inheritdoc}
*/
public function batchUpdate(MassActionInterface $massAction, IterableResultInterface $results, array $data)
{
$this->entityName = $massAction->getOptions()->offsetGet('entityName');
$this->fieldName = empty($data['mass_edit_field']) ? null : $data['mass_edit_field'];
if (empty($this->fieldName)) {
throw new \RuntimeException("Field name was not specified with option 'mass_edit_field'");
}
$this->identifierName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($this->entityName);
$value = $data[$this->fieldName];
$selectedIds = [];
$entitiesCount = 0;
$iteration = 0;
$this->entityManager = $this->doctrineHelper->getEntityManager($this->entityName);
$this->entityManager->beginTransaction();
try {
set_time_limit(0);
foreach ($results as $result) {
/** @var $result ResultRecordInterface */
$selectedIds[] = $result->getValue($this->identifierName);
$iteration++;
if ($iteration % $this->batchSize == 0) {
$entitiesCount += $this->finishBatch($selectedIds, $value);
}
}
if ($iteration % $this->batchSize > 0) {
$entitiesCount += $this->finishBatch($selectedIds, $value);
}
$this->entityManager->commit();
} catch (\Exception $e) {
$this->entityManager->rollback();
throw $e;
}
return $entitiesCount;
}
示例3: postSetData
/**
* @param FormEvent $event
*/
public function postSetData(FormEvent $event)
{
$form = $event->getForm();
if ($form->getParent() || !$form->has($this->fieldName)) {
return;
}
$isEntityExists = false;
$entity = $event->getData();
if ($entity) {
if (!is_object($entity)) {
return;
}
$entityClass = ClassUtils::getClass($entity);
if (!$this->doctrineHelper->isManageableEntity($entityClass)) {
return;
}
$entityIdentifier = $this->doctrineHelper->getEntityManager($entityClass)->getClassMetadata($entityClass)->getIdentifierValues($entity);
$isEntityExists = !empty($entityIdentifier);
}
// if entity exists and assign is not granted - replace field with disabled text field,
// otherwise - set default owner value
if ($isEntityExists) {
$this->replaceOwnerField($form);
} else {
$this->setPredefinedOwner($form);
}
}
示例4: merge
/**
* {@inheritdoc}
*/
public function merge(FieldData $fieldData)
{
$entityData = $fieldData->getEntityData();
$masterEntity = $entityData->getMasterEntity();
$sourceEntity = $fieldData->getSourceEntity();
if ($masterEntity->getId() !== $sourceEntity->getId()) {
$queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId());
$notes = $queryBuilder->getQuery()->getResult();
if (!empty($notes)) {
$entityManager = $this->doctrineHelper->getEntityManager(current($notes));
foreach ($notes as $note) {
$entityManager->remove($note);
}
}
$queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId());
$notes = $queryBuilder->getQuery()->getResult();
if (!empty($notes)) {
foreach ($notes as $note) {
$note->setTarget($masterEntity);
}
}
$fieldMetadata = $fieldData->getMetadata();
$activityClass = $fieldMetadata->get('type');
$entityClass = ClassUtils::getRealClass($sourceEntity);
$queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
$activityListItems = $queryBuilder->getQuery()->getResult();
$activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
$this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
}
}
示例5: guessColumnOptions
/**
* {@inheritdoc}
*/
public function guessColumnOptions($columnName, $entityName, $column)
{
$entityManager = $this->doctrineHelper->getEntityManager($entityName);
$metadata = $entityManager->getClassMetadata($entityName);
$result = [];
if ($metadata->hasField($columnName) && !$metadata->hasAssociation($columnName)) {
$result[Configuration::BASE_CONFIG_KEY] = [Configuration::CONFIG_ENABLE_KEY => true];
}
return $result;
}
示例6: onDuplicateAfter
/**
* Link new product with category from source product
*
* @param ProductDuplicateAfterEvent $event
*/
public function onDuplicateAfter(ProductDuplicateAfterEvent $event)
{
$product = $event->getProduct();
$sourceProduct = $event->getSourceProduct();
$category = $this->getCategoryRepository()->findOneByProduct($sourceProduct);
if ($category !== null) {
$category->addProduct($product);
$objectManager = $this->doctrineHelper->getEntityManager($this->categoryClass);
$objectManager->flush();
}
}
示例7: getEmailOrigins
/**
* @param mixed $userId
* @return EmailOrigin[]
*/
public function getEmailOrigins($userId)
{
if (null === $this->emailOrigins) {
if ($userId) {
$user = $this->doctrineHelper->getEntityManager($this->userClass)->getRepository($this->userClass)->find($userId);
$this->emailOrigins = $user->getEmailOrigins();
} else {
$this->emailOrigins = [];
}
}
return $this->emailOrigins;
}
示例8: isConditionAllowed
/**
* Check ACL for resource.
*
* @param mixed $context
* @return boolean
*/
protected function isConditionAllowed($context)
{
$attributes = $this->contextAccessor->getValue($context, $this->attributes);
$objectOrClass = $this->contextAccessor->getValue($context, $this->objectOrClass);
if (is_object($objectOrClass)) {
$unitOfWork = $this->doctrineHelper->getEntityManager($objectOrClass)->getUnitOfWork();
if (!$unitOfWork->isInIdentityMap($objectOrClass) || $unitOfWork->isScheduledForInsert($objectOrClass)) {
$objectOrClass = 'Entity:' . $this->doctrineHelper->getEntityClass($objectOrClass);
}
}
return $this->securityFacade->isGranted($attributes, $objectOrClass);
}
示例9: createSubordinateIterator
/**
* {@inheritdoc}
*/
protected function createSubordinateIterator($staticSegment)
{
$vars = $this->provider->provideExtendedMergeVars($staticSegment->getMarketingList());
$varNames = array_map(function ($each) {
return $each['name'];
}, $vars);
$qb = $this->doctrineHelper->getEntityManager($this->extendedMergeVarClassName)->getRepository($this->extendedMergeVarClassName)->createQueryBuilder('extendedMergeVar');
$qb->select(['extendedMergeVar.id', $staticSegment->getId() . ' static_segment_id', 'extendedMergeVar.name', $qb->expr()->literal(ExtendedMergeVar::STATE_REMOVE) . ' state']);
$qb->where($qb->expr()->andX($qb->expr()->eq('extendedMergeVar.staticSegment', ':staticSegment'), $qb->expr()->notIn('extendedMergeVar.name', ':vars'), $qb->expr()->neq('extendedMergeVar.state', ':state')))->setParameter('staticSegment', $staticSegment)->setParameter('vars', $varNames)->setParameter('state', ExtendedMergeVar::STATE_DROPPED);
$bufferedIterator = new BufferedQueryResultIterator($qb);
$bufferedIterator->setHydrationMode(AbstractQuery::HYDRATE_ARRAY)->setReverse(true);
return $bufferedIterator;
}
示例10: onDuplicateAfter
/**
* Copy product prices
*
* @param ProductDuplicateAfterEvent $event
*/
public function onDuplicateAfter(ProductDuplicateAfterEvent $event)
{
$product = $event->getProduct();
$sourceProduct = $event->getSourceProduct();
$productPrices = $this->getProductPriceRepository()->getPricesByProduct($sourceProduct);
$objectManager = $this->doctrineHelper->getEntityManager($this->productPriceClass);
foreach ($productPrices as $productPrice) {
$productPriceCopy = clone $productPrice;
$productPriceCopy->setProduct($product);
$objectManager->persist($productPriceCopy);
}
$objectManager->flush();
}
示例11: write
/**
* {@inheritdoc}
*/
public function write(array $items)
{
$entityManager = $this->doctrineHelper->getEntityManager($this->getClassName($items));
foreach ($items as $item) {
$entityManager->persist($item);
$this->detachFixer->fixEntityAssociationFields($item, 1);
}
$entityManager->flush();
$configuration = $this->getConfig();
if (empty($configuration[self::SKIP_CLEAR])) {
$entityManager->clear();
}
}
示例12: getOrCreateFieldsChanges
/**
* @param object $entity
* @param bool $allowCreate
*
* @return FieldsChanges
*/
protected function getOrCreateFieldsChanges($entity, $allowCreate = true)
{
$className = $this->doctrineHelper->getEntityClass($entity);
$identifier = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$em = $this->doctrineHelper->getEntityManager($this->className);
$fieldChanges = $em->getRepository($this->className)->findOneBy(['entityClass' => $className, 'entityId' => $identifier]);
if ($fieldChanges || !$fieldChanges && !$allowCreate) {
return $fieldChanges;
}
$fieldChanges = $this->doctrineHelper->createEntityInstance($this->className)->setEntityClass($className)->setEntityId($identifier);
$em->persist($fieldChanges);
return $fieldChanges;
}
示例13: createQueryBuilder
/**
* @param array $item
* @return QueryBuilder
*/
protected function createQueryBuilder(array $item)
{
$em = $this->doctrineHelper->getEntityManager($this->entityName);
$identifierFieldName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($this->entityName);
$qb = $em->createQueryBuilder();
$qb->select('COUNT(e.' . $identifierFieldName . ') as itemsCount')->from($this->entityName, 'e');
if (array_key_exists($this->field, $item)) {
$qb->andWhere($qb->expr()->notIn('e.' . $this->field, ':items'))->setParameter('items', (array) $item[$this->field]);
}
// Workaround to limit by channel. Channel is not available in second step context.
if (array_key_exists('channel', $item)) {
$qb->andWhere($qb->expr()->eq('e.channel', ':channel'))->setParameter('channel', $item['channel']);
}
return $qb;
}
示例14: onProcessHandleAfter
/**
* @param ProcessHandleEvent $event
*
* @throws \Exception
*/
public function onProcessHandleAfter(ProcessHandleEvent $event)
{
$entity = $event->getProcessData()->get('data');
if (!$entity instanceof MemberActivity) {
return;
}
$this->processCollectorListener->setEnabled(false);
try {
$this->doctrineHelper->getEntityManager($entity)->flush($entity);
} catch (\Exception $e) {
$this->processCollectorListener->setEnabled(true);
throw $e;
}
$this->processCollectorListener->setEnabled(true);
}
示例15: updateValues
/**
* @param Channel $channel
* @param array $values
* @throws \Doctrine\DBAL\ConnectionException
* @throws \Exception
*/
protected function updateValues(Channel $channel, array $values)
{
if (count($values) === 0) {
return;
}
$entityFQCN = $channel->getCustomerIdentity();
$em = $this->doctrineHelper->getEntityManager($entityFQCN);
$idField = $this->doctrineHelper->getSingleEntityIdentifierFieldName($entityFQCN);
$connection = $em->getConnection();
$connection->beginTransaction();
try {
foreach ($values as $id => $value) {
$qb = $em->createQueryBuilder();
$qb->update($entityFQCN, 'e');
foreach ($value as $metricName => $metricValue) {
$qb->set('e.' . $metricName, ':' . $metricName);
$qb->setParameter($metricName, $metricValue);
}
$qb->where($qb->expr()->eq('e.' . $idField, ':id'));
$qb->setParameter('id', $id);
$qb->getQuery()->execute();
}
$connection->commit();
} catch (\Exception $e) {
$connection->rollBack();
throw $e;
}
}