Skip to content
Merged

T186 #120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Block/Widget/Recent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
* Copyright © Magefan (support@magefan.com). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*
* Glory to Ukraine! Glory to the heroes!
Expand Down Expand Up @@ -94,6 +94,24 @@ protected function _preparePostCollection()
if ($category = $this->getCategory()) {
$this->_postCollection->addCategoryFilter($category);
}

if ($tagId = $this->getData('tag_id')) {
$this->_postCollection->addTagFilter($tagId);
}

if ($authorId = $this->getData('author_id')) {
$this->_postCollection->addAuthorFilter($authorId);
}

if ($from = $this->getData('from')) {
$this->_postCollection
->addFieldToFilter('publish_time', array('gteq' => $from . " 00:00:00"));
}

if ($to = $this->getData('to')) {
$this->_postCollection
->addFieldToFilter('publish_time', array('lteq' => $to . " 00:00:00"));
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Magefan\Blog\Model\Config\Source;

/**
* Used in recent post widget
* Used in recent post widget & post edit page
*
*/
class Tag implements \Magento\Framework\Option\ArrayInterface
Expand Down
32 changes: 32 additions & 0 deletions Model/Config/Source/WidgetTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*
* Glory to Ukraine! Glory to the heroes!
*/

namespace Magefan\Blog\Model\Config\Source;

/**
* Used in recent post widget
*
*/
class WidgetTag extends Tag
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
if ($this->options === null) {
parent::toOptionArray();
array_unshift($this->options, ['label' => __('Please select'), 'value' => 0]);
}

return $this->options;
}

}
22 changes: 19 additions & 3 deletions etc/widget.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/**
* Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
* Copyright © Magefan (support@magefan.com). All rights reserved.
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
*
* Glory to Ukraine! Glory to the heroes!
Expand All @@ -24,7 +24,23 @@
<label translate="true">Blog Category</label>
<description translate="true">Leave blank to display posts from all categories.</description>
</parameter>
<parameter name="custom_template" xsi:type="text" visible="true" sort_order="40" >
<parameter name="tag_id" xsi:type="select" source_model="Magefan\Blog\Model\Config\Source\WidgetTag" visible="true" sort_order="40" >
<label translate="true">Blog Tag</label>
<description translate="true">Leave blank to display posts from all tags.</description>
</parameter>
<parameter name="author_id" xsi:type="select" source_model="Magefan\Blog\Model\Config\Source\Author" visible="true" sort_order="50" >
<label translate="true">Blog Author</label>
<description translate="true">Leave blank to display posts from all author.</description>
</parameter>
<parameter name="from" xsi:type="text" visible="true" sort_order="60" >
<label translate="true">Blog Publish Date From</label>
<description translate="true">Please use date format YYYY-MM-DD.</description>
</parameter>
<parameter name="to" xsi:type="text" visible="true" sort_order="70" >
<label translate="true">Blog Publish Date To</label>
<description translate="true">Please use date format YYYY-MM-DD.</description>
</parameter>
<parameter name="custom_template" xsi:type="text" visible="true" sort_order="80" >
<label translate="true">Custom Template</label>
<description translate="true"><![CDATA[
Leave blank to use default template <em>Magefan_Blog::widget/recent.phtml</em>.<br/>
Expand Down Expand Up @@ -54,4 +70,4 @@
</parameter>
</parameters>
</widget>
</widgets>
</widgets>