41 lines
1.4 KiB
PHP
Executable File
41 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace IpSupply\CustomBanner\Block\Widget;
|
|
|
|
use Magento\Framework\View\Element\Template;
|
|
use Magento\Widget\Block\BlockInterface;
|
|
use Magento\Framework\View\Element\Template\Context;
|
|
use Magento\Framework\App\ObjectManager;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use IpSupply\CustomBanner\Model\BannerFactory;
|
|
use Magento\Framework\UrlInterface;
|
|
|
|
class CustomBanner extends Template implements BlockInterface {
|
|
protected $_objectManager;
|
|
protected $_storeManager;
|
|
protected $_bannerFactory;
|
|
|
|
public function __construct(StoreManagerInterface $_storeManager, BannerFactory $_bannerFactory, Context $context, array $data = []) {
|
|
$this->_objectManager = ObjectManager::getInstance();
|
|
$this->_storeManager = $_storeManager;
|
|
$this->_bannerFactory = $_bannerFactory;
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
public function getBannerData() {
|
|
$banner = $this->_bannerFactory->create();
|
|
$bannerData = $banner->getCollection()->addFieldToFilter("status", ["equal" => 'active'])->getData();
|
|
|
|
return $bannerData;
|
|
}
|
|
|
|
function getAssetUrl($asset) {
|
|
$assetRepository = $this->_objectManager->get('Magento\Framework\View\Asset\Repository');
|
|
return $assetRepository->createAsset($asset)->getUrl();
|
|
}
|
|
|
|
public function getImagePath() {
|
|
$imagePath = $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
|
|
return $imagePath;
|
|
}
|
|
} |