Files
2017-11-14 15:04:59 +01:00

34 lines
1.0 KiB
PHP

<?php
namespace Edeclic\News\Block\Widget;
class News extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{
/**
* @var \Edeclic\News\Model\newsFactory
*/
protected $_newsFactory;
protected $_template = 'widget/news.phtml';
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Edeclic\News\Model\NewsFactory $newsFactory
) {
$this->_newsFactory = $newsFactory;
parent::__construct($context);
}
public function getLastestNews()
{
$collection = $this->_newsFactory->create()->getCollection();
$collection->addFieldToFilter('store_ids',array(array('like'=>'%"'.$this->_storeManager->getStore()->getId().'"%')));
$collection->addFieldToFilter('active',1);
$collection->setOrder('date_actu','DESC');
return $collection->getFirstItem();
}
public function getStoreUrl()
{
return $this->_storeManager->getStore()->getBaseUrl();
}
}