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/extmag/shiplab/Block/Adminhtml/Label/View/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Block/Adminhtml/Label/View/GenericButton.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Block\Adminhtml\Label\View;

use Exception;
use Extmag\Shiplab\Api\Data\LabelInterface;
use Extmag\Shiplab\Api\LabelRepositoryInterface;
use Extmag\Shiplab\Helper\Manager;
use Extmag\Shiplab\Helper\Url;
use Extmag\Shiplab\Model\ResourceModel\Label\Collection;
use Magento\Backend\Block\Widget\Context;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem\Driver\File;

class GenericButton
{
    /**
     * @var Context
     */
    protected $context;

    /**
     * @var LabelRepositoryInterface
     */
    protected $entityRepository;

    /**
     * @var Url
     */
    protected $url;

    /**
     * @var File
     */
    protected $file;

    /**
     * @var Manager
     */
    protected $manager;
    /**
     * @var Collection
     */
    protected $entityCollection;

    /**
     * @param Context                  $context
     * @param LabelRepositoryInterface $entityRepository
     * @param Collection               $entityCollection
     * @param Url                      $url
     * @param File                     $file
     * @param Manager                  $manager
     */
    public function __construct(
        Context $context,
        LabelRepositoryInterface $entityRepository,
        Collection $entityCollection,
        Url $url,
        File $file,
        Manager $manager
    ) {
        $this->context          = $context;
        $this->entityRepository = $entityRepository;
        $this->url              = $url;
        $this->file             = $file;
        $this->manager          = $manager;
        $this->entityCollection = $entityCollection;
    }

    /**
     * @return int|null
     */
    public function getEntityId()
    {
        try {
            $entity = $this->getEntity();
            if (!empty($entity)) {
                return $entity->getId();
            }
        } catch (Exception $e) {
        }

        return null;
    }

    /**
     * @return LabelInterface|null
     */
    public function getEntity()
    {
        try {
            $ids = explode(",", $this->context->getRequest()->getParam('entity_id', ""));

            return $this->entityRepository->getById($ids[0]);
        } catch (Exception $e) {
        }

        return null;
    }

    /**
     * @return Collection|null
     */
    public function getEntities()
    {
        try {
            $ids = explode(",", $this->context->getRequest()->getParam('entity_id', ""));

            return $this->entityCollection->addFieldToFilter('entity_id', ['in' => $ids]);
        } catch (Exception $e) {
        }

        return null;
    }

    /**
     * @return array|null
     */
    public function getEntityIds()
    {
        try {
            return explode(",", $this->context->getRequest()->getParam('entity_id', ""));
        } catch (NoSuchEntityException $e) {
        }

        return null;
    }

    /**
     * Generate url by route and parameters
     *
     * @param string $route
     * @param array  $params
     *
     * @return  string
     */
    public function getUrl($route = '', $params = [])
    {
        return $this->context->getUrlBuilder()->getUrl($route, $params);
    }

    /**
     * @param $entities
     * @param $documentType
     * @param $ext
     *
     * @return bool
     * @throws FileSystemException
     */
    protected function isDocumentsExists($entities, $documentType, $ext)
    {
        foreach ($entities as $entity) {
            if ($this->file->isExists(
                $this->url->getMediaPath()
                . '/'
                . $this->url->getExtmagMediaPath(
                    $entity->getCarrierCode(),
                    $documentType,
                    ($ext == '' ? $entity->getExtension() : null)
                )
                . $entity->getMasterId() . '.' . ($ext ?: $entity->getExtension())
            )
            ) {
                return true;
            }
        }

        return false;
    }
}

Spamworldpro Mini