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/pdfdesign-m2/src/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfdesign-m2/src/Model/ImpactOne.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\PdfDesign\Model;

use Fooman\PdfCore\Block\Pdf\DocumentRenderer;
use Fooman\PdfCore\Block\Pdf\DocumentRendererInterface;
use Fooman\PdfCore\Helper\Page;
use Fooman\PdfDesign\Model\Config\HexToRgbConverter;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
 * Design source for Impact One
 */
class ImpactOne extends DefaultDesign
{
    const XML_PATH_ACCENT_COLOUR = 'sales_pdf/impact/accentcolour';
    const XML_PATH_SIDEBAR_COLOUR = 'sales_pdf/impact/sidebarcolour';
    const XML_PATH_SIDEBAR_TEXT_COLOUR = 'sales_pdf/impact/sidebartextcolour';

    const XML_PATH_PAGE_SIDE_MARGINS = 'sales_pdf/impact/marginsides';
    const XML_PATH_PAGE_TOP_MARGIN = 'sales_pdf/impact/margintop';
    const XML_PATH_PAGE_BOTTOM_MARGIN = 'sales_pdf/impact/marginbottom';

    const WIDTH_STRIPE = 0.31;

    /**
     * @var ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * @var HexToRgbConverter
     */
    protected $hexToRgbConverter;

    /**
     * @var Page
     */
    protected $pageHelper;

    /**
     * @param ScopeConfigInterface $scopeConfig
     * @param HexToRgbConverter $hexToRgbConverter
     * @param Page $pageHelper
     * @param array $templateFiles
     * @param string $footerHandle
     */
    public function __construct(
        ScopeConfigInterface $scopeConfig,
        HexToRgbConverter $hexToRgbConverter,
        Page $pageHelper,
        array $templateFiles = [],
        $footerHandle = DocumentRenderer::DEFAULT_FOOTER_LAYOUT_HANDLE
    ) {
        $this->scopeConfig = $scopeConfig;
        $this->hexToRgbConverter = $hexToRgbConverter;
        $this->pageHelper = $pageHelper;
        parent::__construct($templateFiles, $footerHandle);
    }

    public function getLayoutHandle($pdfType)
    {
        return sprintf('fooman_pdfcustomiser_impact_1_%s', $pdfType);
    }

    public function getAccentColour()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_ACCENT_COLOUR,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getSidebarTextColour()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_SIDEBAR_TEXT_COLOUR,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getSidebarColour()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_SIDEBAR_COLOUR,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getSideMargins()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_PAGE_SIDE_MARGINS,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getTopMargin()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_PAGE_TOP_MARGIN,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getBottomMargin()
    {
        return $this->scopeConfig->getValue(
            self::XML_PATH_PAGE_BOTTOM_MARGIN,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $this->getStoreId()
        );
    }

    public function getStripeColourAsRGB()
    {
        return $this->hexToRGBArray($this->getSidebarColour());
    }

    public function hexToRGBArray($hex)
    {
        return $this->hexToRgbConverter->convert($hex);
    }

    public function getSidebarWidth()
    {
        return self::WIDTH_STRIPE;
    }

    public function getCalculatedColumnWidth($index)
    {
        $columnGap = $this->getSideMargins();
        switch ($index) {
            case 1:
                return ($this->getSidebarWidth() * $this->pageHelper->getPageWidth())
                    - $this->getSideMargins()
                    - $columnGap;
            case 2:
                return 2 * $this->getSideMargins();
            case 3:
                return ((1-$this->getSidebarWidth()) * $this->pageHelper->getPageWidth())
                    - $this->getSideMargins()
                    - $columnGap;
        }
    }

    /**
     * @return array
     */
    public function getItemStyling()
    {
        $acctCol = $this->getAccentColour();

        return [
            'header' => [
                'default' => "font-weight:bold;
                line-height: 8mm; 
                border-bottom:5px solid $acctCol;",
                'first'   => "font-weight:bold;
                line-height: 8mm;
                border-bottom:5px solid $acctCol;",
                'last'    => "font-weight:bold;
                line-height: 8mm;
                border-bottom:5px solid $acctCol;"
            ],
            'row'    => [
                'default' => 'border-bottom:0px none transparent;',
                'last'    => "border-bottom:3px solid black;",
                'first'   => 'border-bottom:0px none transparent;'
            ],
            'cell'    => [
                'default' => '',
                'last'    => 'border-top: 5px solid '.$acctCol.'; font-weight: bold; line-height: 8mm;',
                'first'   => 'border-top: 5px solid '.$acctCol.'; font-weight: bold; line-height: 8mm;'
            ],
            'table'  => ['default' => 'padding: 8px 4px;']
        ];
    }

    public function getAccentedCellStyle($isFirst, $isLast)
    {
        if ($isFirst && $isLast) {
            return $this->getItemStyling()['cell']['first'] . ' '. $this->getItemStyling()['cell']['last'];
        }

        if ($isFirst) {
            return $this->getItemStyling()['cell']['first'];
        }

        if ($isLast) {
            return $this->getItemStyling()['cell']['last'];
        }
        return $this->getItemStyling()['cell']['default'];
    }

    public function getSidebarHeadingStyle()
    {
        $primCol = $this->getAccentColour();
        return 'border-top: 5px solid '.$primCol.'; font-weight: bold; line-height: 8mm;';
    }

    public function makePdfAdjustments($pdf, $document)
    {
        $this->applyNewMargins($pdf, $document);
        $pageWidth = $this->pageHelper->getPageWidth();
        $pageHeight = $this->pageHelper->getPageHeight();
        $pdf->setHeaderInstructions(
            ['Rect'=>
                [
                    0,
                    0,
                    $this->getSidebarWidth() * $pageWidth,
                    $pageHeight,
                    'F',
                    '',
                    $this->getStripeColourAsRGB()
                ]
            ]
        );
    }

    protected function applyNewMargins($pdf, $document)
    {
        $pdf->SetMargins(
            $this->getSideMargins(),
            $this->getTopMargin(),
            -1,
            true
        );
        $pdf->setHeaderMargin(0);
        $pdf->setFooterMargin($this->getBottomMargin());

        $pdf->SetAutoPageBreak(true, $this->getBottomPageBreak($pdf, $document));
    }

    protected function getBottomPageBreak($pdf, DocumentRendererInterface $document)
    {
        if ($document->canApplyIntegratedLabelsContent()) {
            return 75;
        }
        return $pdf->getFooterMargin() + 10;
    }
}

Spamworldpro Mini