![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/amasty/product-attachment/Model/File/DataProvider/ |
<?php /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Product Attachments Base for Magento 2 */ namespace Amasty\ProductAttachment\Model\File\DataProvider; use Amasty\ProductAttachment\Model\File\ResourceModel\CollectionFactory; use Amasty\ProductAttachment\Api\Data\FileInterface; use Amasty\ProductAttachment\Model\Icon\GetIconForFile; class Listing extends \Magento\Ui\DataProvider\AbstractDataProvider { /** * @var \Amasty\ProductAttachment\Model\File\ResourceModel\Collection */ protected $collection; /** * @var GetIconForFile */ private $getIconForFile; public function __construct( CollectionFactory $collectionFactory, GetIconForFile $getIconForFile, $name, $primaryFieldName, $requestFieldName, array $meta = [], array $data = [] ) { $this->collection = $collectionFactory->create(); $this->collection->addFileData(); parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->getIconForFile = $getIconForFile; } public function getData() { $data = parent::getData(); if (!empty($data['items'])) { foreach ($data['items'] as &$item) { $item['icon_src'] = $this->getIconForFile->byFileExtension( (string)$item[FileInterface::EXTENSION], (int)$item[FileInterface::ATTACHMENT_TYPE] ) ?: false; $item[FileInterface::SIZE] = $this->getReadableFileSize((int)$item[FileInterface::SIZE]); } } return $data; } /** * @param int $bytes * * @return string */ public function getReadableFileSize($bytes = 0) { $size = ['B', 'kB', 'MB', 'GB', 'TB']; $factor = (int)floor((strlen($bytes) - 1) / 3); if (isset($size[$factor])) { $bytes = sprintf("%.2f", $bytes / pow(1024, $factor)) . ' ' . $size[$factor]; } return $bytes; } }