From 42ebf3e3c9e8d42f70f8c8a08325230c22af83ca Mon Sep 17 00:00:00 2001
From: termos008 <34942603+termos008@users.noreply.github.com>
Date: Fri, 5 Jan 2018 16:11:16 +0200
Subject: [PATCH 1/7] Update Recent.php
---
Block/Widget/Recent.php | 94 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/Block/Widget/Recent.php b/Block/Widget/Recent.php
index b3471b29..27fe77e2 100755
--- a/Block/Widget/Recent.php
+++ b/Block/Widget/Recent.php
@@ -18,7 +18,28 @@ class Recent extends \Magefan\Blog\Block\Post\PostList\AbstractList implements \
* @var \Magefan\Blog\Model\CategoryFactory
*/
protected $_categoryFactory;
+
+ /**
+ * @var \Magefan\Blog\Model\TagFactory
+ */
+ protected $tagFactory;
+
+ /**
+ * @var \Magefan\Blog\Model\Tag
+ */
+ protected $tag;
+
+ /**
+ * @var \Magefan\Blog\Model\AuthorFactory
+ */
+ protected $authorFactory;
+
+ /**
+ * @var \Magefan\Blog\Model\Author
+ */
+ protected $author;
+
/**
* @var \Magefan\Blog\Model\Category
*/
@@ -33,6 +54,8 @@ class Recent extends \Magefan\Blog\Block\Post\PostList\AbstractList implements \
* @param \Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory
* @param \Magefan\Blog\Model\Url $url
* @param \Magefan\Blog\Model\CategoryFactory $categoryFactory
+ * @param \Magefan\Blog\Model\TagFactory $tagFactory
+ * @param \Magefan\Blog\Model\AuthorFactory $authorFactory
* @param array $data
*/
public function __construct(
@@ -42,10 +65,15 @@ public function __construct(
\Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory,
\Magefan\Blog\Model\Url $url,
\Magefan\Blog\Model\CategoryFactory $categoryFactory,
+ \Magefan\Blog\Model\TagFactory $tagFactory,
+ \Magefan\Blog\Model\AuthorFactory $authorFactory,
array $data = []
) {
parent::__construct($context, $coreRegistry, $filterProvider, $postCollectionFactory, $url, $data);
$this->_categoryFactory = $categoryFactory;
+ $this->tagFactory = $tagFactory;
+ $this->authorFactory = $authorFactory;
+
}
/**
@@ -94,6 +122,7 @@ protected function _preparePostCollection()
if ($category = $this->getCategory()) {
$this->_postCollection->addCategoryFilter($category);
}
+
}
/**
@@ -113,6 +142,71 @@ public function getCategory()
$category->setStoreId($storeId);
return $this->_category = $category;
}
+ if ($tag = $this->getTag()) {
+ $this->_postCollection->addTagFilter($tag);
+ }
+
+ if ($author = $this->getAuthor()) {
+ $this->_postCollection->addAuthorFilter($author);
+ }
+
+ if ($this->getData('from')) {
+ $this->_postCollection
+ ->addFieldToFilter('publish_time', array('gteq' => $this->getData('from') . " 00:00:00"));
+ }
+
+ if ($this->getData('to')) {
+ $this->_postCollection
+ ->addFieldToFilter('publish_time', array('lteq' => $this->getData('to') . " 00:00:00"));
+ }
+ }
+
+
+ /**
+ * Retrieve author instance
+ *
+ * @return \Magefan\Blog\Model\Author
+ */
+ public function getAuthor()
+ {
+ if ($this->author === null) {
+ if ($authotId = $this->getData('author_id')) {
+ $author = $this->authorFactory->create();
+ $author->load($authotId);
+
+ return $this->author = $author;
+
+ }
+
+ $this->author = false;
+ }
+
+ return $this->author;
+
+ }
+
+ /**
+ * Retrieve tag instance
+ *
+ * @return \Magefan\Blog\Model\Tag
+ */
+ public function getTag()
+ {
+ if ($this->tag === null) {
+ if ($tagId = $this->getData('tags_id')) {
+
+ $tag = $this->tagFactory->create();
+ $tag->load($tagId);
+
+ return $this->tag = $tag;
+
+ }
+
+ $this->tag = false;
+ }
+
+ return $this->tag;
+
}
$this->_category = false;
From 6eecb94158e2be51601a263a25b76a363aff3f39 Mon Sep 17 00:00:00 2001
From: termos008 <34942603+termos008@users.noreply.github.com>
Date: Fri, 5 Jan 2018 16:12:16 +0200
Subject: [PATCH 2/7] Update Tag.php
---
Model/Config/Source/Tag.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Model/Config/Source/Tag.php b/Model/Config/Source/Tag.php
index f839f7cf..de3b72c0 100755
--- a/Model/Config/Source/Tag.php
+++ b/Model/Config/Source/Tag.php
@@ -44,7 +44,7 @@ public function __construct(
public function toOptionArray()
{
if ($this->options === null) {
- $this->options = [];
+ $this->options = [['label' => __('Please select'), 'value' => 0]];
$collection = $this->tagCollectionFactory->create();
$collection->setOrder('title');
From 5a0ad688f96ba2b53f6ad2392994fe8c34e15c9f Mon Sep 17 00:00:00 2001
From: termos008 <34942603+termos008@users.noreply.github.com>
Date: Fri, 5 Jan 2018 16:13:19 +0200
Subject: [PATCH 3/7] Update AbstractImport.php
---
Model/Import/AbstractImport.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Model/Import/AbstractImport.php b/Model/Import/AbstractImport.php
index a52062b4..01215a50 100644
--- a/Model/Import/AbstractImport.php
+++ b/Model/Import/AbstractImport.php
@@ -1,9 +1,7 @@
Date: Fri, 5 Jan 2018 16:14:39 +0200
Subject: [PATCH 4/7] Update Tag.php
---
Model/Tag.php | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Model/Tag.php b/Model/Tag.php
index d73d1302..ba7c5d39 100755
--- a/Model/Tag.php
+++ b/Model/Tag.php
@@ -87,6 +87,17 @@ public function checkIdentifier($identifier)
{
return $this->load($identifier)->getId();
}
+
+ /**
+ * Retrieve if is visible on store
+ * @return bool
+ */
+ public function isVisibleOnStore($storeId)
+ {
+ return $this->getIsActive()
+ && $this->getData('publish_time') <= $this->getResource()->getDate()->gmtDate()
+ && array_intersect([0, $storeId], $this->getStoreIds());
+ }
/**
* Retrieve catgegory url route path
From bcb6865290c924cc28d8eb6c183d0a7fa80907ed Mon Sep 17 00:00:00 2001
From: termos008 <34942603+termos008@users.noreply.github.com>
Date: Fri, 5 Jan 2018 16:16:43 +0200
Subject: [PATCH 5/7] Update widget.xml
---
etc/widget.xml | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/etc/widget.xml b/etc/widget.xml
index dc3b5144..5a40073e 100755
--- a/etc/widget.xml
+++ b/etc/widget.xml
@@ -24,7 +24,24 @@
Leave blank to display posts from all categories.
-
+
+
+ Leave blank to display posts from all tags.
+
+
+
+ Leave blank to display posts from all author.
+
+
+
+ Please use date format YYYY-MM-DD.
+
+
+
+ Please use date format YYYY-MM-DD.
+
+
+
Magefan_Blog::widget/recent.phtml.
@@ -54,4 +71,4 @@
-
\ No newline at end of file
+
From 3c0763b5393b7a5e5c5425f3008be2d6d71d40ea Mon Sep 17 00:00:00 2001
From: Andriy Martynovskyj
Date: Fri, 5 Jan 2018 17:17:58 +0200
Subject: [PATCH 6/7] add object manager for author and tag filter
---
Block/Widget/Recent.php | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/Block/Widget/Recent.php b/Block/Widget/Recent.php
index 27fe77e2..f1be1fb0 100755
--- a/Block/Widget/Recent.php
+++ b/Block/Widget/Recent.php
@@ -65,15 +65,16 @@ public function __construct(
\Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory,
\Magefan\Blog\Model\Url $url,
\Magefan\Blog\Model\CategoryFactory $categoryFactory,
- \Magefan\Blog\Model\TagFactory $tagFactory,
- \Magefan\Blog\Model\AuthorFactory $authorFactory,
+ $tagFactory = null,
+ $authorFactory = null,
array $data = []
) {
parent::__construct($context, $coreRegistry, $filterProvider, $postCollectionFactory, $url, $data);
$this->_categoryFactory = $categoryFactory;
- $this->tagFactory = $tagFactory;
- $this->authorFactory = $authorFactory;
+ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
+ $this->tagFactory = $objectManager->create(\Magefan\Blog\Model\TagFactory::class);
+ $this->authorFactory = $objectManager->create(\Magefan\Blog\Model\AuthorFactory::class);
}
/**
@@ -142,14 +143,16 @@ public function getCategory()
$category->setStoreId($storeId);
return $this->_category = $category;
}
- if ($tag = $this->getTag()) {
+ }
+ }
+
+ if ($tag = $this->getTag()) {
$this->_postCollection->addTagFilter($tag);
}
if ($author = $this->getAuthor()) {
$this->_postCollection->addAuthorFilter($author);
}
-
if ($this->getData('from')) {
$this->_postCollection
->addFieldToFilter('publish_time', array('gteq' => $this->getData('from') . " 00:00:00"));
@@ -207,12 +210,6 @@ public function getTag()
return $this->tag;
- }
-
- $this->_category = false;
- }
-
- return $this->_category;
}
/**
From f3465929864527d74d3f5f39fdf4006091f07efc Mon Sep 17 00:00:00 2001
From: Ihor Vansach
Date: Wed, 10 Jan 2018 14:24:33 +0200
Subject: [PATCH 7/7] Changes for recent blog post widget after code review
---
Block/Widget/Recent.php | 115 ++++++------------------------
Model/Config/Source/Tag.php | 4 +-
Model/Config/Source/WidgetTag.php | 32 +++++++++
Model/Import/AbstractImport.php | 4 +-
Model/Tag.php | 11 ---
etc/widget.xml | 5 +-
6 files changed, 60 insertions(+), 111 deletions(-)
create mode 100755 Model/Config/Source/WidgetTag.php
diff --git a/Block/Widget/Recent.php b/Block/Widget/Recent.php
index f1be1fb0..14b50f14 100755
--- a/Block/Widget/Recent.php
+++ b/Block/Widget/Recent.php
@@ -1,6 +1,6 @@
_categoryFactory = $categoryFactory;
-
- $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- $this->tagFactory = $objectManager->create(\Magefan\Blog\Model\TagFactory::class);
- $this->authorFactory = $objectManager->create(\Magefan\Blog\Model\AuthorFactory::class);
}
/**
@@ -123,7 +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"));
+ }
}
/**
@@ -144,72 +132,11 @@ public function getCategory()
return $this->_category = $category;
}
}
- }
-
- if ($tag = $this->getTag()) {
- $this->_postCollection->addTagFilter($tag);
- }
-
- if ($author = $this->getAuthor()) {
- $this->_postCollection->addAuthorFilter($author);
- }
- if ($this->getData('from')) {
- $this->_postCollection
- ->addFieldToFilter('publish_time', array('gteq' => $this->getData('from') . " 00:00:00"));
- }
-
- if ($this->getData('to')) {
- $this->_postCollection
- ->addFieldToFilter('publish_time', array('lteq' => $this->getData('to') . " 00:00:00"));
- }
- }
-
-
- /**
- * Retrieve author instance
- *
- * @return \Magefan\Blog\Model\Author
- */
- public function getAuthor()
- {
- if ($this->author === null) {
- if ($authotId = $this->getData('author_id')) {
- $author = $this->authorFactory->create();
- $author->load($authotId);
-
- return $this->author = $author;
-
- }
-
- $this->author = false;
- }
-
- return $this->author;
-
- }
-
- /**
- * Retrieve tag instance
- *
- * @return \Magefan\Blog\Model\Tag
- */
- public function getTag()
- {
- if ($this->tag === null) {
- if ($tagId = $this->getData('tags_id')) {
-
- $tag = $this->tagFactory->create();
- $tag->load($tagId);
-
- return $this->tag = $tag;
-
- }
- $this->tag = false;
+ $this->_category = false;
}
- return $this->tag;
-
+ return $this->_category;
}
/**
diff --git a/Model/Config/Source/Tag.php b/Model/Config/Source/Tag.php
index de3b72c0..f924019f 100755
--- a/Model/Config/Source/Tag.php
+++ b/Model/Config/Source/Tag.php
@@ -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
@@ -44,7 +44,7 @@ public function __construct(
public function toOptionArray()
{
if ($this->options === null) {
- $this->options = [['label' => __('Please select'), 'value' => 0]];
+ $this->options = [];
$collection = $this->tagCollectionFactory->create();
$collection->setOrder('title');
diff --git a/Model/Config/Source/WidgetTag.php b/Model/Config/Source/WidgetTag.php
new file mode 100755
index 00000000..abcb4291
--- /dev/null
+++ b/Model/Config/Source/WidgetTag.php
@@ -0,0 +1,32 @@
+options === null) {
+ parent::toOptionArray();
+ array_unshift($this->options, ['label' => __('Please select'), 'value' => 0]);
+ }
+
+ return $this->options;
+ }
+
+}
diff --git a/Model/Import/AbstractImport.php b/Model/Import/AbstractImport.php
index 01215a50..a52062b4 100644
--- a/Model/Import/AbstractImport.php
+++ b/Model/Import/AbstractImport.php
@@ -1,7 +1,9 @@
load($identifier)->getId();
}
-
- /**
- * Retrieve if is visible on store
- * @return bool
- */
- public function isVisibleOnStore($storeId)
- {
- return $this->getIsActive()
- && $this->getData('publish_time') <= $this->getResource()->getDate()->gmtDate()
- && array_intersect([0, $storeId], $this->getStoreIds());
- }
/**
* Retrieve catgegory url route path
diff --git a/etc/widget.xml b/etc/widget.xml
index 5a40073e..de92ba05 100755
--- a/etc/widget.xml
+++ b/etc/widget.xml
@@ -1,7 +1,7 @@