/** * @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->attachmentAssociationHelper->isAttachmentAssociationEnabled(ClassUtils::getClass($entity)); }
/** * Checks if the entity can has notes * * @param object $entity * @return bool * @deprecated since 1.9. Use {@see Oro\Bundle\AttachmentBundle\Tools\AttachmentAssociationHelper} instead */ public function isAttachmentAssociationEnabled($entity) { if (!is_object($entity)) { return false; } return $this->attachmentAssociationHelper->isAttachmentAssociationEnabled(ClassUtils::getClass($entity)); }
public function testIsAttachmentAssociationEnabledForEnabledButNotAccessibleAssociationButWithAccessibleFalse() { $entityClass = 'Test\\Entity'; $config = new Config(new EntityConfigId('attachment', $entityClass)); $config->set('enabled', true); $this->configManager->expects($this->once())->method('hasConfig')->with($entityClass)->willReturn(true); $this->configManager->expects($this->once())->method('getEntityConfig')->with('attachment', $entityClass)->willReturn($config); $this->configManager->expects($this->never())->method('getFieldConfig'); $this->assertTrue($this->attachmentAssociationHelper->isAttachmentAssociationEnabled($entityClass, false)); }
/** * @param object $entity * * @return Attachment[] */ public function getEntityAttachments($entity) { $entityClass = ClassUtils::getClass($entity); if ($this->attachmentAssociationHelper->isAttachmentAssociationEnabled($entityClass)) { $fieldName = ExtendHelper::buildAssociationName($entityClass); $repo = $this->em->getRepository('OroAttachmentBundle:Attachment'); $qb = $repo->createQueryBuilder('a'); $qb->leftJoin('a.' . $fieldName, 'entity')->where('entity.id = :entityId')->setParameter('entityId', $entity->getId()); return $qb->getQuery()->getResult(); } return []; }
/** * Check is attached file to target entity * * @param EmailAttachment $attachment * @param object $target * * @return bool */ public function isAttached($attachment, $target) { $targetEntityClass = ClassUtils::getClass($target); if ($this->attachmentAssociationHelper->isAttachmentAssociationEnabled($targetEntityClass)) { $attached = $this->em->getRepository('OroAttachmentBundle:Attachment')->findOneBy([ExtendHelper::buildAssociationName($targetEntityClass) => $target, 'file' => $attachment->getFile()]); return null !== $attached; } return false; }