Esempio n. 1
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);
 }
Esempio n. 2
0
 public function testIsAttachmentAssociationEnabled()
 {
     $config = new Config(new EntityConfigId('attachment', 'stdClass'));
     $config->set('enabled', true);
     $this->attachmentConfigProvider->expects($this->once())->method('hasConfig')->with('stdClass')->will($this->returnValue(true));
     $this->attachmentConfigProvider->expects($this->once())->method('getConfig')->with('stdClass')->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName('stdClass'))->will($this->returnValue(true));
     $this->assertTrue($this->attachmentConfig->isAttachmentAssociationEnabled(new \stdClass()));
 }
Esempio n. 3
0
 /**
  * @param object $entity
  *
  * @return Attachment[]
  */
 public function getEntityAttachments($entity)
 {
     if ($this->attachmentConfig->isAttachmentAssociationEnabled($entity)) {
         $className = ClassUtils::getClass($entity);
         $fieldName = ExtendHelper::buildAssociationName($className);
         $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->attachmentConfig->isAttachmentAssociationEnabled($target)) {
         $attached = $this->em->getRepository('OroAttachmentBundle:Attachment')->findOneBy([ExtendHelper::buildAssociationName($targetEntityClass) => $target, 'file' => $attachment->getFile()]);
         return null !== $attached;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Delegated method
  *
  * @param object $entity
  * @return bool
  */
 public function isAttachmentAssociationEnabled($entity)
 {
     return $this->config->isAttachmentAssociationEnabled($entity);
 }