本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Config\ConfigManager::getEntityMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigManager::getEntityMetadata方法的具体用法?PHP ConfigManager::getEntityMetadata怎么用?PHP ConfigManager::getEntityMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Config\ConfigManager
的用法示例。
在下文中一共展示了ConfigManager::getEntityMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetEntityMetadata
public function testGetEntityMetadata()
{
$this->assertNull($this->configManager->getEntityMetadata('SomeUndefinedClass'));
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
$this->assertSame($metadata, $this->configManager->getEntityMetadata(self::ENTITY_CLASS));
}
示例2: getConfiguration
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
$configuration = parent::getConfiguration();
$className = $this->source->getEntity();
$metadata = $this->configManager->getEntityMetadata($className);
if (!$metadata || empty($metadata->routeView)) {
return $configuration;
}
$fromPart = $configuration->offsetGetByPath('[source][query][from]');
$entityAlias = null;
$doctrineMetadata = $this->doctrine->getManagerForClass($className)->getClassMetadata($className);
$identifiers = $doctrineMetadata->getIdentifier();
$primaryKey = array_shift($identifiers);
foreach ($fromPart as $piece) {
if ($piece['table'] == $className) {
$entityAlias = $piece['alias'];
break;
}
}
if (!$entityAlias || !$primaryKey || count($identifiers) > 1 || !$this->isActionSupported($primaryKey)) {
return $configuration;
}
$viewAction = ['view' => ['type' => 'navigate', 'label' => 'oro.report.datagrid.view', 'acl_resource' => 'VIEW;entity:' . $className, 'icon' => 'eye-open', 'link' => 'view_link', 'rowAction' => true]];
$properties = [$primaryKey => null, 'view_link' => ['type' => 'url', 'route' => $metadata->routeView, 'params' => [$primaryKey]]];
$configuration->offsetAddToArrayByPath('[source][query][select]', ["{$entityAlias}.{$primaryKey}"]);
$configuration->offsetAddToArrayByPath('[properties]', $properties);
$configuration->offsetAddToArrayByPath('[actions]', $viewAction);
return $configuration;
}
示例3: getFromNameLink
/**
* @param Email $email
*
* @return bool|string
*/
protected function getFromNameLink(Email $email)
{
$path = false;
if ($email->getFromEmailAddress() && $email->getFromEmailAddress()->getOwner()) {
$className = $email->getFromEmailAddress()->getOwner()->getClass();
$routeName = $this->configManager->getEntityMetadata($className)->getRoute('view', false);
$path = $this->router->generate($routeName, ['id' => $email->getFromEmailAddress()->getOwner()->getId()]);
}
return $path;
}
示例4: getUrl
/**
* Generate rout for entity (using entity config)
*
* @param Reminder $reminder
* @return string
*/
public function getUrl(Reminder $reminder)
{
$metadata = $this->manager->getEntityMetadata($reminder->getRelatedEntityClassName());
if (isset($metadata)) {
if (!empty($metadata->routeView)) {
return $this->router->generate($metadata->routeView, array('id' => $reminder->getRelatedEntityId()));
}
if (!empty($metadata->routeName)) {
return $this->router->generate($metadata->routeName);
}
}
return '';
}
示例5: getData
/**
* {@inheritdoc}
*/
public function getData(ActivityList $activityListEntity)
{
/** @var Email $email */
$email = $headEmail = $this->doctrineRegistryLink->getService()->getRepository($activityListEntity->getRelatedActivityClass())->find($activityListEntity->getRelatedActivityId());
if ($email->isHead() && $email->getThread()) {
$headEmail = $this->emailThreadProvider->getHeadEmail($this->doctrineHelper->getEntityManager($activityListEntity->getRelatedActivityClass()), $email);
}
$data = ['ownerName' => $email->getFromName(), 'ownerLink' => null, 'entityId' => $email->getId(), 'headOwnerName' => $headEmail->getFromName(), 'headSubject' => $headEmail->getSubject(), 'headSentAt' => $headEmail->getSentAt()->format('c'), 'isHead' => $email->isHead() && $email->getThread(), 'treadId' => $email->getThread() ? $email->getThread()->getId() : null];
if ($email->getThread()) {
$emails = $email->getThread()->getEmails();
// if there are just two email - add replayedEmailId to use on client side
if (count($emails) === 2) {
$data['replayedEmailId'] = $emails[0]->getId();
}
}
if ($email->getFromEmailAddress()->getHasOwner()) {
$owner = $email->getFromEmailAddress()->getOwner();
$data['headOwnerName'] = $data['ownerName'] = $this->entityNameResolver->getName($owner);
$route = $this->configManager->getEntityMetadata(ClassUtils::getClass($owner))->getRoute('view');
$securityFacade = $this->securityFacadeLink->getService();
if (null !== $route && $securityFacade->isGranted('VIEW', $owner)) {
$id = $this->doctrineHelper->getSingleEntityIdentifier($owner);
try {
$data['ownerLink'] = $this->router->generate($route, ['id' => $id]);
} catch (RouteNotFoundException $e) {
// Do not set owner link if route is not found.
}
}
}
return $data;
}
示例6: getClassRoute
/**
* @param string $className The entity class name
* @param string $routeType Route Type
* @param bool $strict Should exception be thrown if no route of given type found
*
* @return string
*/
public function getClassRoute($className, $routeType = 'view', $strict = false)
{
if (!$this->configManager->hasConfig($className)) {
return null;
}
return $this->configManager->getEntityMetadata($className)->getRoute($routeType, $strict);
}
示例7: getEmailContext
/**
* Returns the context for the given email
*
* @param Email $email
*
* @return array
*/
public function getEmailContext(Email $email)
{
$criteria = Criteria::create();
$criteria->andWhere(Criteria::expr()->eq('id', $email->getId()));
$qb = $this->activityManager->getActivityTargetsQueryBuilder($this->class, $criteria);
if (null === $qb) {
return [];
}
$result = $qb->getQuery()->getResult();
if (empty($result)) {
return $result;
}
$currentUser = $this->securityFacade->getLoggedUser();
$currentUserClass = ClassUtils::getClass($currentUser);
$currentUserId = $currentUser->getId();
$result = array_values(array_filter($result, function ($item) use($currentUserClass, $currentUserId) {
return !($item['entity'] === $currentUserClass && $item['id'] == $currentUserId);
}));
foreach ($result as &$item) {
$route = $this->configManager->getEntityMetadata($item['entity'])->getRoute();
$item['entityId'] = $email->getId();
$item['targetId'] = $item['id'];
$item['targetClassName'] = $this->entityClassNameHelper->getUrlSafeClassName($item['entity']);
$item['icon'] = $this->configManager->getProvider('entity')->getConfig($item['entity'])->get('icon');
$item['link'] = $route ? $this->router->generate($route, ['id' => $item['id']]) : null;
unset($item['id'], $item['entity']);
}
return $result;
}
示例8: getActivityContext
/**
* Returns the context for the given activity class and id
*
* @param string $class The FQCN of the activity entity
* @param $id
*
* @return array
*/
public function getActivityContext($class, $id)
{
$currentUser = $this->securityTokenStorage->getToken()->getUser();
$userClass = ClassUtils::getClass($currentUser);
$entity = $this->doctrineHelper->getEntity($class, $id);
$result = [];
if (!$entity || !$entity instanceof ActivityInterface) {
return $result;
}
$targets = $entity->getActivityTargetEntities();
$entityProvider = $this->configManager->getProvider('entity');
foreach ($targets as $target) {
$targetClass = ClassUtils::getClass($target);
$targetId = $target->getId();
if ($userClass === $targetClass && $currentUser->getId() === $targetId) {
continue;
}
$item = [];
$config = $entityProvider->getConfig($targetClass);
$metadata = $this->configManager->getEntityMetadata($targetClass);
$safeClassName = $this->entityClassNameHelper->getUrlSafeClassName($targetClass);
$link = null;
if ($metadata) {
$link = $this->router->generate($metadata->getRoute(), ['id' => $targetId]);
} elseif ($link === null && ExtendHelper::isCustomEntity($targetClass)) {
// Generate view link for the custom entity
$link = $this->router->generate('oro_entity_view', ['id' => $targetId, 'entityName' => $safeClassName]);
}
if ($fields = $this->mapper->getEntityMapParameter($targetClass, 'title_fields')) {
$text = [];
foreach ($fields as $field) {
$text[] = $this->mapper->getFieldValue($target, $field);
}
$item['title'] = implode(' ', $text);
} else {
$item['title'] = $this->translator->trans('oro.entity.item', ['%id%' => $targetId]);
}
$item['activityClassAlias'] = $this->entityAliasResolver->getPluralAlias($class);
$item['entityId'] = $id;
$item['targetId'] = $targetId;
$item['targetClassName'] = $safeClassName;
$item['icon'] = $config->get('icon');
$item['link'] = $link;
$result[] = $item;
}
return $result;
}
示例9: getRegularEntityViewRouteOptions
/**
* @param string $entityClassName
* @param mixed $id
*
* @return array
*/
protected function getRegularEntityViewRouteOptions($entityClassName, $id = null)
{
$routeOptions = ['route' => false, 'route_params' => false];
/** @var EntityMetadata $metadata */
$metadata = $this->configManager->getEntityMetadata($entityClassName);
if ($metadata && $metadata->routeView) {
$routeOptions['route'] = $metadata->routeView;
$routeOptions['route_params'] = ['id' => $id];
}
return $routeOptions;
}
示例10: getActivityContext
/**
* Returns the context for the given activity class and id
*
* @param string $class The FQCN of the activity entity
* @param $id
*
* @return array
*/
public function getActivityContext($class, $id)
{
$criteria = Criteria::create();
$criteria->andWhere(Criteria::expr()->eq('id', $id));
$currentUser = $this->securityTokenStorage->getToken()->getUser();
$userClass = ClassUtils::getClass($currentUser);
$queryBuilder = $this->activityManager->getActivityTargetsQueryBuilder($class, $criteria, null, null, null, null, function (QueryBuilder $qb, $targetEntityClass) use($currentUser, $userClass) {
if ($targetEntityClass === $userClass) {
// Exclude current user from result
$qb->andWhere($qb->expr()->neq(QueryUtils::getSelectExprByAlias($qb, 'entityId'), $currentUser->getId()));
}
});
if (null === $queryBuilder) {
return [];
}
$result = $queryBuilder->getQuery()->getResult();
if (empty($result)) {
return $result;
}
$entityProvider = $this->configManager->getProvider('entity');
foreach ($result as &$item) {
$config = $entityProvider->getConfig($item['entity']);
$metadata = $this->configManager->getEntityMetadata($item['entity']);
$safeClassName = $this->entityClassNameHelper->getUrlSafeClassName($item['entity']);
$link = null;
if ($metadata) {
$link = $this->router->generate($metadata->getRoute(), ['id' => $item['id']]);
} elseif ($link === null && ExtendHelper::isCustomEntity($item['entity'])) {
// Generate view link for the custom entity
$link = $this->router->generate('oro_entity_view', ['id' => $item['id'], 'entityName' => $safeClassName]);
}
$item['activityClassAlias'] = $this->entityAliasResolver->getPluralAlias($class);
$item['entityId'] = $id;
$item['targetId'] = $item['id'];
$item['targetClassName'] = $safeClassName;
$item['icon'] = $config->get('icon');
$item['link'] = $link;
unset($item['id'], $item['entity']);
}
return $result;
}
示例11: getClassRoute
/**
* @param string $className The entity class name
* @param string $routeType Route Type
* @param bool $strict Should exception be thrown if no route of given type found
*
* @return string|null
*/
public function getClassRoute($className, $routeType = 'view', $strict = false)
{
if (!$this->configManager->hasConfig($className)) {
return null;
}
$entityMetadata = $this->configManager->getEntityMetadata($className);
if (!$entityMetadata) {
return null;
}
$route = $entityMetadata->getRoute($routeType, $strict);
return $route && $this->hasRoute($route) ? $route : null;
}
示例12: findValueByPrimaryKey
/**
* Search entities by primary key
*
* @param $keys[]
*
* @return array
*/
public function findValueByPrimaryKey($keys)
{
$entityMetadata = $this->entityConfigManager->getEntityMetadata($this->class);
$keyField = $this->dictionaryHelper->getNamePrimaryKeyField($this->getMetadata());
$searchFields = $this->dictionaryHelper->getSearchFields($this->getMetadata(), $entityMetadata);
$representationField = $this->dictionaryHelper->getRepresentationField($this->getMetadata(), $entityMetadata);
$qb = $this->getListQueryBuilder(-1, 1, [], null, []);
$qb->andWhere('e.' . $keyField . ' in (:keys)');
$qb->setParameter('keys', $keys);
$query = $qb->getQuery();
$results = $query->getResult();
return $this->prepareData($results, $keyField, $searchFields, $representationField);
}
示例13: getClassRoute
/**
* @param string $className The entity class name
* @param string $routeType Route Type
* @param bool $strict Should exception be thrown if no route of given type found
*
* @return string
*/
public function getClassRoute($className, $routeType = 'view', $strict = false)
{
if (!$this->configManager->hasConfig($className)) {
return null;
}
$route = $this->configManager->getEntityMetadata($className)->getRoute($routeType, $strict);
if ($collection = $this->router->getRouteCollection()) {
if ($collection->get($route) === null) {
return null;
}
}
return $route;
}
示例14: setOwnerLink
/**
* @param EmailOwnerInterface $owner
* @param $data
*
* @return mixed
*/
protected function setOwnerLink($owner, $data)
{
$route = $this->configManager->getEntityMetadata(ClassUtils::getClass($owner))->getRoute('view');
$securityFacade = $this->securityFacadeLink->getService();
if (null !== $route && $securityFacade->isGranted('VIEW', $owner)) {
$id = $this->doctrineHelper->getSingleEntityIdentifier($owner);
try {
$data['ownerLink'] = $this->router->generate($route, ['id' => $id]);
} catch (RouteNotFoundException $e) {
// Do not set owner link if route is not found.
}
}
return $data;
}
示例15: getEntityRouteOptions
/**
* @param string $entityClassName
*
* @return array
*/
protected function getEntityRouteOptions($entityClassName)
{
$route = false;
$routeParams = false;
if (class_exists($entityClassName)) {
/** @var EntityMetadata $metadata */
$metadata = $this->configManager->getEntityMetadata($entityClassName);
if ($metadata && $metadata->routeView) {
$route = $metadata->routeView;
$routeParams = ['id' => null];
}
$relationExtendConfig = $this->extendProvider->getConfig($entityClassName);
if ($relationExtendConfig->is('owner', ExtendScope::OWNER_CUSTOM)) {
$route = $this->entityViewRoute;
$routeParams = ['entityName' => str_replace('\\', '_', $entityClassName), 'id' => null];
}
}
return ['route' => $route, 'route_params' => $routeParams];
}