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/cartforge.co/app/code/Webkul/PrivateShop/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/Webkul/PrivateShop/Model/PrivateGroupRepository.php
<?php
/**
 * Webkul Software
 *
 * @category  Webkul
 * @package   Webkul_PrivateShop
 * @author    Webkul Software Private Limited
 * @copyright Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */

namespace Webkul\PrivateShop\Model;

use Magento\Framework\Api\SortOrder;
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Framework\Exception\NoSuchEntityException;
use Webkul\PrivateShop\Model\ResourceModel\PrivateGroup as ResourcePrivateGroup;
use Magento\Framework\Exception\CouldNotSaveException;
use Webkul\PrivateShop\Api\Data\PrivateGroupSearchResultsInterfaceFactory;
use Webkul\PrivateShop\Api\Data\PrivateGroupInterfaceFactory;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Api\DataObjectHelper;
use Webkul\PrivateShop\Api\PrivateGroupRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Webkul\PrivateShop\Model\ResourceModel\PrivateGroup\CollectionFactory as PrivateGroupCollectionFactory;

class PrivateGroupRepository implements PrivateGroupRepositoryInterface
{
    /**
     * @var ResourcePrivateGroup
     */
    protected $resource;

    /**
     * @var PrivateGroupCollectionFactory
     */
    protected $privateGroupCollectionFactory;

    /**
     * @var PrivateGroupInterfaceFactory
     */
    protected $dataPrivateGroupFactory;

    /**
     * @var DataObjectHelper
     */
    protected $dataObjectHelper;

    /**
     * @var PrivateGroupFactory
     */
    protected $privateGroupFactory;

    /**
     * @var StoreManagerInterface
     */
    private $storeManager;

    /**
     * @var PrivateGroupSearchResultsInterfaceFactory
     */
    protected $searchResultsFactory;

    /**
     * @var DataObjectProcessor
     */
    protected $dataObjectProcessor;

    /**
     * @param ResourcePrivateGroup $resource
     * @param PrivateGroupFactory $privateGroupFactory
     * @param PrivateGroupInterfaceFactory $dataPrivateGroupFactory
     * @param PrivateGroupCollectionFactory $privateGroupCollectionFactory
     * @param PrivateGroupSearchResultsInterfaceFactory $searchResultsFactory
     * @param DataObjectHelper $dataObjectHelper
     * @param DataObjectProcessor $dataObjectProcessor
     * @param StoreManagerInterface $storeManager
     */
    public function __construct(
        ResourcePrivateGroup $resource,
        PrivateGroupFactory $privateGroupFactory,
        PrivateGroupInterfaceFactory $dataPrivateGroupFactory,
        PrivateGroupCollectionFactory $privateGroupCollectionFactory,
        PrivateGroupSearchResultsInterfaceFactory $searchResultsFactory,
        DataObjectHelper $dataObjectHelper,
        DataObjectProcessor $dataObjectProcessor,
        StoreManagerInterface $storeManager
    ) {
        $this->resource = $resource;
        $this->privateGroupFactory = $privateGroupFactory;
        $this->privateGroupCollectionFactory = $privateGroupCollectionFactory;
        $this->searchResultsFactory = $searchResultsFactory;
        $this->dataObjectHelper = $dataObjectHelper;
        $this->dataPrivateGroupFactory = $dataPrivateGroupFactory;
        $this->dataObjectProcessor = $dataObjectProcessor;
        $this->storeManager = $storeManager;
    }

    /**
     * Save PrivateGroup
     *
     * @param \Webkul\PrivateShop\Api\Data\PrivateGroupInterface $privateGroup
     * @return \Webkul\PrivateShop\Api\Data\PrivateGroupInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function save(
        \Webkul\PrivateShop\Api\Data\PrivateGroupInterface $privateGroup
    ) {
        try {
            $this->resource->save($privateGroup);
        } catch (\Exception $exception) {
            throw new CouldNotSaveException(__(
                'Could not save the privateGroup: %1',
                $exception->getMessage()
            ));
        }
        return $privateGroup;
    }

    /**
     * Retrieve PrivateGroup By Group Id
     *
     * @param string $privateGroupId
     * @return \Webkul\PrivateShop\Api\Data\PrivateGroupInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getById($privateGroupId)
    {
        $privateGroup = $this->privateGroupFactory->create();
        $this->resource->load($privateGroup, $privateGroupId);
        if (!$privateGroup->getId()) {
            throw new NoSuchEntityException(__('PrivateGroup with id "%1" does not exist.', $privateGroupId));
        }
        return $privateGroup;
    }

    /**
     * Retrieve PrivateGroup matching the specified criteria.
     *
     * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
     * @return \Webkul\PrivateShop\Api\Data\PrivateGroupSearchResultsInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getList(
        \Magento\Framework\Api\SearchCriteriaInterface $criteria
    ) {
        $collection = $this->privateGroupCollectionFactory->create();
        foreach ($criteria->getFilterGroups() as $filterGroup) {
            $fields = [];
            $conditions = [];
            foreach ($filterGroup->getFilters() as $filter) {
                if ($filter->getField() === 'store_id') {
                    $collection->addStoreFilter($filter->getValue(), false);
                    continue;
                }
                $fields[] = $filter->getField();
                $condition = $filter->getConditionType() ?: 'eq';
                $conditions[] = [$condition => $filter->getValue()];
            }
            $collection->addFieldToFilter($fields, $conditions);
        }
        
        $sortOrders = $criteria->getSortOrders();
        if ($sortOrders) {
            /** @var SortOrder $sortOrder */
            foreach ($sortOrders as $sortOrder) {
                $collection->addOrder(
                    $sortOrder->getField(),
                    ($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
                );
            }
        }
        $collection->setCurPage($criteria->getCurrentPage());
        $collection->setPageSize($criteria->getPageSize());
        
        $searchResults = $this->searchResultsFactory->create();
        $searchResults->setSearchCriteria($criteria);
        $searchResults->setTotalCount($collection->getSize());
        $searchResults->setItems($collection->getItems());
        return $searchResults;
    }

    /**
     * Delete PrivateGroup
     *
     * @param \Webkul\PrivateShop\Api\Data\PrivateGroupInterface $privateGroup
     * @return bool true on success
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function delete(
        \Webkul\PrivateShop\Api\Data\PrivateGroupInterface $privateGroup
    ) {
        try {
            $this->resource->delete($privateGroup);
        } catch (\Exception $exception) {
            throw new CouldNotDeleteException(__(
                'Could not delete the PrivateGroup: %1',
                $exception->getMessage()
            ));
        }
        return true;
    }

    /**
     * Delete PrivateGroup by ID
     *
     * @param string $privateGroupId
     * @return bool true on success
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function deleteById($privateGroupId)
    {
        return $this->delete($this->getById($privateGroupId));
    }
}

Spamworldpro Mini