/**
  * @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);
     }
 }
 /**
  * Checks if the entity can has notes
  *
  * @param object $entity
  * @return bool
  */
 public function isNoteAssociationEnabled($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
         return false;
     }
     return $this->noteAssociationHelper->isNoteAssociationEnabled(ClassUtils::getClass($entity));
 }
 /**
  * Checks if the entity can have comments
  *
  * @param object|null $entity
  *
  * @return bool
  */
 public function isApplicable($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) {
         return false;
     }
     return $this->commentAssociationHelper->isCommentAssociationEnabled(ClassUtils::getClass($entity));
 }
Beispiel #4
0
 /**
  * Delegated method
  *
  * @param object $entity
  * @return bool
  */
 public function isAttachmentAssociationEnabled($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
         return false;
     }
     return $this->config->isAttachmentAssociationEnabled($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (empty($options['data_class'])) {
         return;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return;
     }
     if (!$this->entityConfigProvider->hasConfig($className)) {
         return;
     }
     $uniqueKeys = $this->entityConfigProvider->getConfig($className)->get('unique_key');
     if (empty($uniqueKeys)) {
         return;
     }
     /* @var \Symfony\Component\Validator\Mapping\ClassMetadata $validatorMetadata */
     $validatorMetadata = $this->validator->getMetadataFor($className);
     foreach ($uniqueKeys['keys'] as $uniqueKey) {
         $fields = $uniqueKey['key'];
         $labels = array_map(function ($fieldName) use($className) {
             $label = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
             return $this->translator->trans($label);
         }, $fields);
         $constraint = new UniqueEntity(['fields' => $fields, 'errorPath' => '', 'message' => $this->translator->transChoice('oro.entity.validation.unique_field', sizeof($fields), ['%field%' => implode(', ', $labels)])]);
         $validatorMetadata->addConstraint($constraint);
     }
 }
 /**
  * Checks if the entity can have comments
  *
  * @param object|null $entity
  *
  * @return bool
  */
 public function isApplicable($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->commentConfigProvider->hasConfig($className) && $this->commentConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Comment::ENTITY_NAME, ExtendHelper::buildAssociationName($className));
 }
Beispiel #7
0
 /**
  * Checks if the entity can has notes
  *
  * @param object $entity
  * @return bool
  */
 public function isNoteAssociationEnabled($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->noteConfigProvider->hasConfig($className) && $this->noteConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Note::ENTITY_NAME, ExtendHelper::buildAssociationName($className));
 }
 /**
  * @param string $entityName
  *
  * @return bool
  */
 protected function isValidEntityClass($entityName)
 {
     try {
         $entityName = $this->entityClassNameHelper->resolveEntityClass($entityName);
     } catch (EntityAliasNotFoundException $e) {
         return false;
     }
     return $this->doctrineHelper->isManageableEntity($entityName);
 }
Beispiel #9
0
 /**
  * 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));
 }
Beispiel #10
0
 /**
  * Compare two values for equality
  *
  * @param mixed $left
  * @param mixed $right
  * @return boolean
  */
 protected function doCompare($left, $right)
 {
     if (is_object($left) && is_object($right)) {
         $leftClass = $this->doctrineHelper->getEntityClass($left);
         $rightClass = $this->doctrineHelper->getEntityClass($right);
         if ($leftClass == $rightClass && $this->doctrineHelper->isManageableEntity($left) && $this->doctrineHelper->isManageableEntity($right)) {
             $leftIdentifier = $this->doctrineHelper->getEntityIdentifier($left);
             $rightIdentifier = $this->doctrineHelper->getEntityIdentifier($right);
             return $leftIdentifier == $rightIdentifier;
         }
     }
     return $left == $right;
 }
 /**
  * @param array|\Traversable $values
  * @return array
  */
 protected function convertToPlainArray($values)
 {
     $result = array();
     foreach ($values as $key => $value) {
         if (is_object($value) && $this->doctrineHelper->isManageableEntity($value)) {
             $result[$key] = $this->doctrineHelper->getEntityIdentifier($value);
         } elseif (is_array($value) || $value instanceof \Traversable) {
             $result[$key] = $this->convertToPlainArray($value);
         } else {
             $result[$key] = $value;
         }
     }
     return $result;
 }
Beispiel #12
0
 /**
  * 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;
 }
 /**
  *
  * @param object $entity
  * @return bool
  */
 public function isApplicable($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || $this->doctrineHelper->isNewEntity($entity)) {
         return false;
     }
     //$allowedValues = $this->configProvider->getAllowed();
     $allowedSection = $this->getAllowedSection();
     $className = ClassUtils::getClass($entity);
     $allowedSection = $allowedSection['allowed'];
     foreach ($allowedSection as $allowedValue) {
         if ($allowedValue == $className) {
             return true;
         }
     }
     //echo $className;die();
     return false;
 }
Beispiel #14
0
 /**
  * Get metadata for entity
  *
  * @param object|string $entity
  *
  * @return bool|OwnershipMetadataInterface
  * @throws \LogicException
  */
 protected function getMetadata($entity)
 {
     if (is_object($entity)) {
         $entity = ClassUtils::getClass($entity);
     }
     if (!$this->doctrineHelper->isManageableEntity($entity)) {
         return false;
     }
     $metadata = $this->ownershipMetadataProvider->getMetadata($entity);
     return $metadata->hasOwner() ? $metadata : false;
 }
Beispiel #15
0
 /**
  * @param array $options
  *
  * @return bool
  */
 protected function isApplicable(array $options)
 {
     if ($options['contexts_disabled'] || empty($options['data_class'])) {
         return false;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return false;
     }
     $activities = $this->activityManager->getActivityTypes();
     return in_array($className, $activities, true);
 }
 /**
  * @param array $options
  *
  * @return bool
  */
 protected function isApplicable(array $options)
 {
     if ($options['dynamic_fields_disabled'] || empty($options['data_class'])) {
         return false;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return false;
     }
     if (!$this->configManager->getProvider('extend')->hasConfig($className)) {
         return false;
     }
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function supportsNormalization($data, $format = null)
 {
     return is_object($data) && $this->doctrineHelper->isManageableEntity($data);
 }
 public function testIsManageableEntityForNotManageableEntity()
 {
     $entity = new ItemStubProxy();
     $this->registry->expects($this->once())->method('getManagerForClass')->with($this->doctrineHelper->getEntityClass($entity))->will($this->returnValue(null));
     $this->assertFalse($this->doctrineHelper->isManageableEntity($entity));
 }