11<?php
22/**
3- * Copyright © 2015-2017 Ihor Vansach (ihor @magefan.com). All rights reserved.
3+ * Copyright © Magefan (support @magefan.com). All rights reserved.
44 * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
55 *
66 * Glory to Ukraine! Glory to the heroes!
@@ -18,28 +18,7 @@ class Recent extends \Magefan\Blog\Block\Post\PostList\AbstractList implements \
1818 * @var \Magefan\Blog\Model\CategoryFactory
1919 */
2020 protected $ _categoryFactory ;
21-
22- /**
23- * @var \Magefan\Blog\Model\TagFactory
24- */
25- protected $ tagFactory ;
26-
27- /**
28- * @var \Magefan\Blog\Model\Tag
29- */
30- protected $ tag ;
31-
32- /**
33- * @var \Magefan\Blog\Model\AuthorFactory
34- */
35- protected $ authorFactory ;
3621
37- /**
38- * @var \Magefan\Blog\Model\Author
39- */
40- protected $ author ;
41-
42-
4322 /**
4423 * @var \Magefan\Blog\Model\Category
4524 */
@@ -54,8 +33,6 @@ class Recent extends \Magefan\Blog\Block\Post\PostList\AbstractList implements \
5433 * @param \Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory
5534 * @param \Magefan\Blog\Model\Url $url
5635 * @param \Magefan\Blog\Model\CategoryFactory $categoryFactory
57- * @param \Magefan\Blog\Model\TagFactory $tagFactory
58- * @param \Magefan\Blog\Model\AuthorFactory $authorFactory
5936 * @param array $data
6037 */
6138 public function __construct (
@@ -65,16 +42,10 @@ public function __construct(
6542 \Magefan \Blog \Model \ResourceModel \Post \CollectionFactory $ postCollectionFactory ,
6643 \Magefan \Blog \Model \Url $ url ,
6744 \Magefan \Blog \Model \CategoryFactory $ categoryFactory ,
68- $ tagFactory = null ,
69- $ authorFactory = null ,
7045 array $ data = []
7146 ) {
7247 parent ::__construct ($ context , $ coreRegistry , $ filterProvider , $ postCollectionFactory , $ url , $ data );
7348 $ this ->_categoryFactory = $ categoryFactory ;
74-
75- $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
76- $ this ->tagFactory = $ objectManager ->create (\Magefan \Blog \Model \TagFactory::class);
77- $ this ->authorFactory = $ objectManager ->create (\Magefan \Blog \Model \AuthorFactory::class);
7849 }
7950
8051 /**
@@ -123,7 +94,24 @@ protected function _preparePostCollection()
12394 if ($ category = $ this ->getCategory ()) {
12495 $ this ->_postCollection ->addCategoryFilter ($ category );
12596 }
126-
97+
98+ if ($ tagId = $ this ->getData ('tag_id ' )) {
99+ $ this ->_postCollection ->addTagFilter ($ tagId );
100+ }
101+
102+ if ($ authorId = $ this ->getData ('author_id ' )) {
103+ $ this ->_postCollection ->addAuthorFilter ($ authorId );
104+ }
105+
106+ if ($ from = $ this ->getData ('from ' )) {
107+ $ this ->_postCollection
108+ ->addFieldToFilter ('publish_time ' , array ('gteq ' => $ from . " 00:00:00 " ));
109+ }
110+
111+ if ($ to = $ this ->getData ('to ' )) {
112+ $ this ->_postCollection
113+ ->addFieldToFilter ('publish_time ' , array ('lteq ' => $ to . " 00:00:00 " ));
114+ }
127115 }
128116
129117 /**
@@ -144,72 +132,11 @@ public function getCategory()
144132 return $ this ->_category = $ category ;
145133 }
146134 }
147- }
148-
149- if ($ tag = $ this ->getTag ()) {
150- $ this ->_postCollection ->addTagFilter ($ tag );
151- }
152-
153- if ($ author = $ this ->getAuthor ()) {
154- $ this ->_postCollection ->addAuthorFilter ($ author );
155- }
156- if ($ this ->getData ('from ' )) {
157- $ this ->_postCollection
158- ->addFieldToFilter ('publish_time ' , array ('gteq ' => $ this ->getData ('from ' ) . " 00:00:00 " ));
159- }
160-
161- if ($ this ->getData ('to ' )) {
162- $ this ->_postCollection
163- ->addFieldToFilter ('publish_time ' , array ('lteq ' => $ this ->getData ('to ' ) . " 00:00:00 " ));
164- }
165- }
166-
167-
168- /**
169- * Retrieve author instance
170- *
171- * @return \Magefan\Blog\Model\Author
172- */
173- public function getAuthor ()
174- {
175- if ($ this ->author === null ) {
176- if ($ authotId = $ this ->getData ('author_id ' )) {
177- $ author = $ this ->authorFactory ->create ();
178- $ author ->load ($ authotId );
179-
180- return $ this ->author = $ author ;
181-
182- }
183-
184- $ this ->author = false ;
185- }
186-
187- return $ this ->author ;
188-
189- }
190-
191- /**
192- * Retrieve tag instance
193- *
194- * @return \Magefan\Blog\Model\Tag
195- */
196- public function getTag ()
197- {
198- if ($ this ->tag === null ) {
199- if ($ tagId = $ this ->getData ('tags_id ' )) {
200-
201- $ tag = $ this ->tagFactory ->create ();
202- $ tag ->load ($ tagId );
203-
204- return $ this ->tag = $ tag ;
205-
206- }
207135
208- $ this ->tag = false ;
136+ $ this ->_category = false ;
209137 }
210138
211- return $ this ->tag ;
212-
139+ return $ this ->_category ;
213140 }
214141
215142 /**
0 commit comments