Spamworldpro Mini Shell
Spamworldpro


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/fooman/pdfcore-m2/src/Block/Pdf/Column/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfcore-m2/src/Block/Pdf/Column/Swatch.php
<?php
/**
 * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz)
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Fooman\PdfCore\Block\Pdf\Column;

use Fooman\PdfCore\Helper\ParamKey;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterface;
use Magento\Backend\Block\Template\Context;
use Magento\Swatches\Model\Swatch as MagentoSwatch;
use Magento\Swatches\Helper\Media as SwatchMediaHelper;
use Magento\Swatches\Helper\Data as SwatchHelper;

class Swatch extends \Fooman\PdfCore\Block\Pdf\Column implements \Fooman\PdfCore\Block\Pdf\ColumnInterface
{
    public const DEFAULT_WIDTH = 12;
    public const DEFAULT_TITLE = 'Swatch';
    public const COLUMN_TYPE = 'fooman_checkbox';

    protected $swatchMediaHelper;
    protected $swatchHelper;

    /**
     * @var ReadInterface
     */
    protected $mediaDirectory;

    /**
     * @var ParamKey
     */
    protected $paramKeyHelper;

    protected $storeId;

    public function __construct(
        Context $context,
        SwatchMediaHelper $swatchMediaHelper,
        SwatchHelper $swatchHelper,
        ParamKey $paramKeyHelper,
        Filesystem $filesystem,
        array $data = []
    ) {
        $this->swatchMediaHelper = $swatchMediaHelper;
        $this->swatchHelper = $swatchHelper;
        $this->paramKeyHelper = $paramKeyHelper;
        $this->mediaDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
        parent::__construct($context, $data);
    }

    public function getGetter()
    {
        return [$this, 'getSwatch'];
    }

    public function getSwatch($row)
    {
        $html = '';
        $this->storeId = $row->getStoreId();
        $orderItem = $this->getOrderItem($row);
        $attributesInfo = $orderItem->getProductOptionByCode('attributes_info');
        if ($attributesInfo) {
            foreach ($attributesInfo as $attributeInfo) {
                $swatches = $this->swatchHelper->getSwatchesByOptionsId([$attributeInfo['option_value']]);
                $html.= $this->processSwatches($swatches);
            }
        }

        return $html;
    }

    private function processSwatches($swatches)
    {
        $html = '';
        if ($swatches) {
            foreach ($swatches as $swatch) {
                $html .= $this->processSwatch($swatch);
            }
        }
        return $html;
    }

    private function processSwatch($swatch)
    {
        switch ($swatch['type']) {
            case MagentoSwatch::SWATCH_TYPE_VISUAL_COLOR:
                $svgParams = sprintf(
                    '@<svg width="10mm" height="10mm"><rect width="10mm" height="10mm" 
                    style="fill:%s;stroke-width:2;stroke:rgb(0,0,0)" /></svg>',
                    $swatch['value']
                );
                return sprintf(
                    '<div align="%s"><tcpdf method="ImageSVG" %s /></div>',
                    $this->getAlignment() ? $this->getAlignment() : 'left',
                    $this->paramKeyHelper->getEncodedParams([$svgParams])
                );

            case MagentoSwatch::SWATCH_TYPE_TEXTUAL:
                return sprintf(
                    '<div align="%s">%s</div>',
                    $this->getAlignment() ? $this->getAlignment() : 'left',
                    $swatch['value']
                );

            case MagentoSwatch::SWATCH_TYPE_VISUAL_IMAGE:
                $dim = $this->getImageDimensions();
                $imagePath = $this->mediaDirectory->getAbsolutePath(
                    $this->swatchMediaHelper->getAttributeSwatchPath($swatch['value'])
                );
                $params = [
                    $imagePath,
                    '',
                    '',
                    $this->getMaxImageWidth(),
                    $dim['image'],
                    '',
                    '',
                    '',
                    true,
                    300,
                    '',
                    false,
                    false,
                    0,
                    true
                ];
                return sprintf(
                    '<div align="%s"><tcpdf method="Image" %s /></div><span style="line-height:%s;"></span>',
                    $this->getAlignment() ? $this->getAlignment() : 'left',
                    $this->paramKeyHelper->getEncodedParams($params),
                    $dim['spacer']
                );
        }
        return '';
    }

    private function getMaxImageWidth()
    {
        return ($this->getAvailablePageWidth($this->storeId) * $this->getCalculatedWidth()/100);
    }

    private function getImageDimensions($size = 'default')
    {
        $sizes = [
            'large'      => ['image' => '25', 'spacer' => '25mm'],
            'xtra-large' => ['image' => '40', 'spacer' => '40mm'],
            'default'    => ['image' => '15', 'spacer' => '15mm'],
            'small'      => ['image' => '12', 'spacer' => '12mm'],
            'xtra-small' => ['image' => '8', 'spacer' => '8mm']
        ];
        if (isset($sizes[$size])) {
            return $sizes[$size];
        }
        return $sizes['default'];
    }
}

Spamworldpro Mini