/** * Returns array of special entity data which is used, for example, in "Who has access" datagrid, * "oro_share_select" form type search result. * * @param object $object * * @return array */ public function getEntityDetails($object) { $id = $label = $details = $image = $avatar = $classLabel = null; if ($object instanceof Organization) { $id = $object->getId(); $label = $object->getName(); $image = 'avatar-organization-small.png'; $classLabel = $this->translator->trans('oro.organization.entity_label'); $details = $classLabel; } elseif ($object instanceof BusinessUnit) { $id = $object->getId(); $label = $object->getName(); $image = 'avatar-business-unit-small.png'; $classLabel = $this->translator->trans('oro.organization.businessunit.entity_label'); $details = $classLabel . ' ' . $this->translator->trans('oro.security.datagrid.share_grid_row_details_from') . ' ' . $object->getOrganization()->getName(); } elseif ($object instanceof User) { $id = $object->getId(); $label = $object->getFirstName() . ' ' . $object->getLastName(); $image = 'avatar-small.png'; $classLabel = $this->translator->trans('oro.user.entity_label'); $avatar = $object->getAvatar() ? $this->attachmentManager->getResizedImageUrl($object->getAvatar(), AttachmentManager::SMALL_IMAGE_WIDTH, AttachmentManager::SMALL_IMAGE_HEIGHT) : null; $details = $classLabel . ' ' . $this->translator->trans('oro.security.datagrid.share_grid_row_details_from') . ' ' . $object->getOwner()->getName(); } return ['id' => $id, 'label' => $label, 'image' => $image, 'avatar' => $avatar, 'details' => $details, 'classLabel' => $classLabel]; }
/** * {@inheritdoc} */ public function format($parameter, array $formatterArguments = []) { $height = AttachmentManager::DEFAULT_IMAGE_HEIGHT; if (array_key_exists(self::HEIGHT_ATTRIBUTE, $formatterArguments)) { $height = (int) $formatterArguments[self::HEIGHT_ATTRIBUTE]; } $width = AttachmentManager::DEFAULT_IMAGE_WIDTH; if (array_key_exists(self::WIDTH_ATTRIBUTE, $formatterArguments)) { $width = (int) $formatterArguments[self::WIDTH_ATTRIBUTE]; } return $this->manager->getResizedImageUrl($parameter, $width, $height, Router::ABSOLUTE_URL); }
/** * {@inheritdoc} */ public function format($parameter, array $formatterArguments = []) { $height = AttachmentManager::DEFAULT_IMAGE_HEIGHT; if (array_key_exists(self::HEIGHT_ATTRIBUTE, $formatterArguments)) { $height = (int) $formatterArguments[self::HEIGHT_ATTRIBUTE]; } $width = AttachmentManager::DEFAULT_IMAGE_WIDTH; if (array_key_exists(self::WIDTH_ATTRIBUTE, $formatterArguments)) { $width = (int) $formatterArguments[self::WIDTH_ATTRIBUTE]; } $title = $parameter->getOriginalFilename(); if (array_key_exists(self::TITLE_ATTRIBUTE, $formatterArguments)) { $title = $formatterArguments[self::TITLE_ATTRIBUTE]; } return sprintf('<a href="%s">%s</a>', $this->manager->getResizedImageUrl($parameter, $width, $height, Router::ABSOLUTE_URL), $title); }
/** * Get resized avatar * * @param User $user * * @return string */ protected function getCommentAvatarImageUrl($user) { $attachment = PropertyAccess::createPropertyAccessor()->getValue($user, self::AVATAR_FIELD_NAME); if ($attachment && $attachment->getFilename()) { $entityClass = ClassUtils::getRealClass($user); $config = $this->configManager->getProvider('attachment')->getConfig($entityClass, self::AVATAR_FIELD_NAME); return ['avatarUrl' => $this->attachmentManager->getResizedImageUrl($attachment, $config->get('width'), $config->get('height'))]; } return []; }
/** * Get Image html block * * @param \Twig_Environment $environment * @param object $parentEntity * @param mixed $attachment * @param string|object $entityClass * @param string $fieldName * @return string */ public function getImageView(\Twig_Environment $environment, $parentEntity, $attachment = null, $entityClass = null, $fieldName = '') { /** * @todo: should be refactored in BAP-5637 */ if (is_int($attachment)) { $attachment = $this->getFileById($attachment); } if ($attachment && $attachment->getFilename()) { $width = self::DEFAULT_THUMB_SIZE; $height = self::DEFAULT_THUMB_SIZE; if ($entityClass && $fieldName) { if (is_object($entityClass)) { $entityClass = ClassUtils::getRealClass($entityClass); } $config = $this->attachmentConfigProvider->getConfig($entityClass, $fieldName); $width = $config->get('width'); $height = $config->get('height'); } return $environment->loadTemplate(self::IMAGES_TEMPLATE)->render(['imagePath' => $this->manager->getResizedImageUrl($attachment, $width, $height), 'url' => $this->manager->getFileUrl($parentEntity, $fieldName, $attachment, 'download', true), 'fileName' => $attachment->getOriginalFilename()]); } return ''; }
public function testGetResizedImageUrl() { $this->attachment->setId(1); $this->router->expects($this->once())->method('generate')->with('oro_resize_attachment', ['width' => 100, 'height' => 50, 'id' => 1, 'filename' => 'testFile.txt']); $this->attachmentManager->getResizedImageUrl($this->attachment, 100, 50); }