本文整理汇总了PHP中Oro\Bundle\EntityBundle\ORM\DoctrineHelper::getSingleEntityIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP DoctrineHelper::getSingleEntityIdentifier方法的具体用法?PHP DoctrineHelper::getSingleEntityIdentifier怎么用?PHP DoctrineHelper::getSingleEntityIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityBundle\ORM\DoctrineHelper
的用法示例。
在下文中一共展示了DoctrineHelper::getSingleEntityIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: debug
/**
* @param string $message
* @param ProcessTrigger $trigger
* @param ProcessData $data
*/
public function debug($message, ProcessTrigger $trigger, ProcessData $data)
{
if ($this->logger) {
$context = array('definition' => $trigger->getDefinition()->getName(), 'event' => $trigger->getEvent(), 'entityId' => $this->doctrineHelper->getSingleEntityIdentifier($data['data'], false));
$this->logger->debug($message, $context);
}
}
示例2: updateAclIdentities
/**
* @param WorkflowItem $workflowItem
* @return WorkflowItem
* @throws WorkflowException
*/
public function updateAclIdentities(WorkflowItem $workflowItem)
{
$workflow = $this->workflowRegistry->getWorkflow($workflowItem->getWorkflowName());
$definition = $workflowItem->getDefinition();
$currentStepName = $workflowItem->getCurrentStep()->getName();
$aclIdentities = array();
foreach ($definition->getEntityAcls() as $entityAcl) {
if ($entityAcl->getStep()->getName() == $currentStepName) {
$attributeName = $entityAcl->getAttribute();
$attribute = $workflow->getAttributeManager()->getAttribute($attributeName);
$entity = $workflowItem->getData()->get($attributeName);
if (!$entity) {
continue;
}
if (!is_object($entity)) {
throw new WorkflowException(sprintf('Value of attribute "%s" must be an object', $attributeName));
}
$aclIdentity = new WorkflowEntityAclIdentity();
$aclIdentity->setAcl($entityAcl)->setEntityClass($attribute->getOption('class'))->setEntityId($this->doctrineHelper->getSingleEntityIdentifier($entity));
$aclIdentities[] = $aclIdentity;
}
}
$workflowItem->setAclIdentities($aclIdentities);
return $workflowItem;
}
示例3: 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;
}
示例4: onFlush
/**
* Collect activities changes
*
* @param OnFlushEventArgs $args
*/
public function onFlush(OnFlushEventArgs $args)
{
$entitiesToDelete = $args->getEntityManager()->getUnitOfWork()->getScheduledEntityDeletions();
$entitiesToUpdate = $args->getEntityManager()->getUnitOfWork()->getScheduledEntityUpdates();
if (!empty($entitiesToDelete) || !empty($entitiesToUpdate)) {
foreach ($entitiesToDelete as $entity) {
$class = $this->doctrineHelper->getEntityClass($entity);
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$key = $class . '_' . $id;
if ($this->activityContactProvider->isSupportedEntity($class) && !isset($this->deletedEntities[$key])) {
$targets = $entity->getActivityTargetEntities();
$targetsInfo = [];
foreach ($targets as $target) {
$targetsInfo[] = ['class' => $this->doctrineHelper->getEntityClass($target), 'id' => $this->doctrineHelper->getSingleEntityIdentifier($target), 'direction' => $this->activityContactProvider->getActivityDirection($entity, $target)];
}
$this->deletedEntities[$key] = ['class' => $class, 'id' => $id, 'contactDate' => $this->activityContactProvider->getActivityDate($entity), 'targets' => $targetsInfo];
}
}
foreach ($entitiesToUpdate as $entity) {
$class = $this->doctrineHelper->getEntityClass($entity);
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$key = $class . '_' . $id;
if ($this->activityContactProvider->isSupportedEntity($class) && !isset($this->updatedEntities[$key])) {
$changes = $args->getEntityManager()->getUnitOfWork()->getEntityChangeSet($entity);
$isDirectionChanged = $this->activityContactProvider->getActivityDirectionProvider($entity)->isDirectionChanged($changes);
$targets = $entity->getActivityTargetEntities();
$targetsInfo = [];
foreach ($targets as $target) {
$targetsInfo[] = ['class' => $this->doctrineHelper->getEntityClass($target), 'id' => $this->doctrineHelper->getSingleEntityIdentifier($target), 'direction' => $this->activityContactProvider->getActivityDirection($entity, $target), 'is_direction_changed' => $isDirectionChanged];
}
$this->updatedEntities[$key] = ['class' => $class, 'id' => $id, 'contactDate' => $this->activityContactProvider->getActivityDate($entity), 'targets' => $targetsInfo];
}
}
}
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($this->request->get(ProductDataStorage::STORAGE_KEY)) {
$entity = isset($options['data']) ? $options['data'] : null;
if ($entity instanceof $this->dataClass && !$this->doctrineHelper->getSingleEntityIdentifier($entity)) {
$this->fillData($entity);
}
}
}
示例6: isApplicable
/**
* Checks if the entity can have activities
*
* @param object|null $entity
* @return bool
*/
public function isApplicable($entity = null)
{
if (null === $entity || !is_object($entity)) {
return false;
}
$entityClass = $this->doctrineHelper->getEntityClass($entity);
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$activityListRepo = $this->doctrine->getRepository('OroActivityListBundle:ActivityList');
return in_array($entityClass, $this->activityListProvider->getTargetEntityClasses()) || (bool) $activityListRepo->getRecordsCountForTargetClassAndId($entityClass, $id);
}
示例7: send
/**
* {@inheritdoc}
*/
public function send(EmailCampaign $campaign, $entity, array $from, array $to)
{
$entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$marketingList = $campaign->getMarketingList();
/** @var EmailTemplate $template */
$template = $campaign->getTransportSettings()->getSettingsBag()->get('template');
list($subjectRendered, $templateRendered) = $this->emailRenderer->compileMessage($template, ['entity' => $entity]);
$emailModel = new Email();
$emailModel->setType($template->getType())->setFrom($this->buildFullEmailAddress($from))->setEntityClass($marketingList->getEntity())->setEntityId($entityId)->setTo($to)->setSubject($subjectRendered)->setBody($templateRendered);
$this->processor->process($emailModel);
}
示例8: isApplicable
/**
* Checks if the entity can have activities
*
* @param object|null $entity
* @param int|null $pageType
* @return bool
*/
public function isApplicable($entity = null, $pageType = null)
{
if ($pageType === null || !is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
return false;
}
$pageType = (int) $pageType;
$id = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$entityClass = $this->doctrineHelper->getEntityClass($entity);
$activityListRepo = $this->doctrine->getRepository('OroActivityListBundle:ActivityList');
return $this->isAllowedOnPage($entity, $pageType) && (in_array($entityClass, $this->activityListProvider->getTargetEntityClasses()) || (bool) $activityListRepo->getRecordsCountForTargetClassAndId($entityClass, $id));
}
示例9: 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;
}
示例10: refreshEntity
/**
* @param object $entity
* @return object|null
*/
protected function refreshEntity($entity)
{
if ($entity instanceof Proxy && !$entity->__isInitialized()) {
$entity->__load();
}
if (!$this->doctrineHelper->getSingleEntityIdentifier($entity)) {
return null;
}
$entityClass = ClassUtils::getClass($entity);
/** @var EntityManager $entityManager */
$entityManager = $this->registry->getManagerForClass($entityClass);
return $entityManager->merge($entity);
}
示例11: normalize
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = array())
{
/** @var ProcessData $object */
$processJob = $this->getProcessJob($context);
$entity = $object['data'];
if (!$entity || $processJob->getProcessTrigger()->getEvent() == ProcessTrigger::EVENT_DELETE) {
$processJob->setEntityId(null);
} else {
$entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$processJob->setEntityId($entityId);
}
return $this->serializer->normalize($object->getValues(), $format, $context);
}
示例12: updateWorkflowItemEntityRelation
/**
* Set workflow item entity ID
*
* @param LifecycleEventArgs $args
* @throws WorkflowException
*/
protected function updateWorkflowItemEntityRelation(LifecycleEventArgs $args)
{
$workflowItem = $args->getEntity();
if ($workflowItem instanceof WorkflowItem && !$workflowItem->getEntityId()) {
$entity = $workflowItem->getEntity();
if (!$entity) {
throw new WorkflowException('Workflow item does not contain related entity');
}
$entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity);
$workflowItem->setEntityId($entityId);
$unitOfWork = $args->getEntityManager()->getUnitOfWork();
$unitOfWork->scheduleExtraUpdate($workflowItem, array('entityId' => array(null, $entityId)));
}
}
示例13: refreshEntity
/**
* @param object $entity
* @return object|null
*/
protected function refreshEntity($entity)
{
$entityClass = ClassUtils::getClass($entity);
$entityId = $this->doctrineHelper->getSingleEntityIdentifier($entity);
/** @var EntityManager $entityManager */
$entityManager = $this->registry->getManagerForClass($entityClass);
if (!$entityId) {
return null;
}
if ($entity instanceof Proxy && !$entity->__isInitialized()) {
// We cannot use $entity->__load(); because of bug BAP-7851
return $entityManager->find($entityClass, $entityId);
}
return $entityManager->merge($entity);
}
示例14: addInitialElements
/**
* @param FormView $view
* @param FormInterface $form
* @param ConfigInterface $extendConfig
*/
protected function addInitialElements(FormView $view, FormInterface $form, ConfigInterface $extendConfig)
{
$data = $form->getData();
if (!is_object($data)) {
return;
}
$dataId = $this->doctrineHelper->getSingleEntityIdentifier($data);
/**
* 0 is default id value for oro_entity_relation
* we need to set it if entity is new
*/
$dataId = $dataId == null ? 0 : $dataId;
/** @var FieldConfigId $extendConfigId */
$extendConfigId = $extendConfig->getId();
$className = $extendConfigId->getClassName();
$fieldName = $extendConfigId->getFieldName();
$view->children[$fieldName]->vars['grid_url'] = $this->router->generate('oro_entity_relation', ['id' => $dataId, 'entityName' => str_replace('\\', '_', $className), 'fieldName' => $fieldName]);
$defaultEntity = null;
if (!$extendConfig->is('without_default')) {
$defaultEntity = FieldAccessor::getValue($data, ExtendConfigDumper::DEFAULT_PREFIX . $fieldName);
}
$selectedCollection = FieldAccessor::getValue($data, $fieldName);
if ($dataId) {
$view->children[$fieldName]->vars['initial_elements'] = $this->getInitialElements($selectedCollection, $defaultEntity, $extendConfig);
}
}
示例15: isApplicable
/**
* Checks if the entity can have activities
*
* @param object|null $entity
* @param int|null $pageType
*
* @return bool
*/
public function isApplicable($entity = null, $pageType = null)
{
if (null === $pageType || !is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
return false;
}
$entityClass = $this->doctrineHelper->getEntityClass($entity);
if (isset($this->applicableCache[$entityClass])) {
return $this->applicableCache[$entityClass];
}
$result = false;
if ($this->configManager->hasConfig($entityClass) && $this->isAllowedOnPage($entityClass, $pageType) && $this->hasApplicableActivityAssociations($entityClass)) {
$result = in_array($entityClass, $this->activityListProvider->getTargetEntityClasses(), true) || !$this->isActivityListEmpty($entityClass, $this->doctrineHelper->getSingleEntityIdentifier($entity));
}
$this->applicableCache[$entityClass] = $result;
return $result;
}