Skip to content

Commit 12b48cf

Browse files
committed
create tags logical
1 parent b518b36 commit 12b48cf

File tree

27 files changed

+866
-40
lines changed

27 files changed

+866
-40
lines changed

Block/Adminhtml/Comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magefan\Blog\Block\Adminhtml;
1010

1111
/**
12-
* Admin blog post
12+
* Admin blog comment
1313
*/
1414
class Comment extends \Magento\Backend\Block\Widget\Grid\Container
1515
{

Block/Adminhtml/Tag.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Block\Adminhtml;
10+
11+
/**
12+
* Admin blog tag
13+
*/
14+
class Tag extends \Magento\Backend\Block\Widget\Grid\Container
15+
{
16+
/**
17+
* Constructor
18+
*
19+
* @return void
20+
*/
21+
protected function _construct()
22+
{
23+
$this->_controller = 'adminhtml_tag';
24+
$this->_blockGroup = 'Magefan_Blog';
25+
$this->_headerText = __('Tag');
26+
$this->_addButtonLabel = __('Add New Tag');
27+
28+
parent::_construct();
29+
}
30+
31+
/**
32+
* @return $this
33+
*/
34+
protected function _prepareLayout()
35+
{
36+
37+
$onClick = "setLocation('" . $this->getUrl('*/import') . "')";
38+
39+
$this->getToolbar()->addChild(
40+
'options_button',
41+
\Magento\Backend\Block\Widget\Button::class,
42+
['label' => __('Import Tags'), 'onclick' => $onClick]
43+
);
44+
45+
return parent::_prepareLayout();
46+
}
47+
48+
}

Block/Sidebar/TagClaud.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,29 @@ public function __construct(
5858
public function getTags()
5959
{
6060
if ($this->_tags === null) {
61-
$this->_tags = $this->_tagCollectionFactory->create();
61+
$this->_tags = $this->_tagCollectionFactory->create()->addActiveFilter();
62+
63+
if (count($this->_tags)) {
6264
$resource = $this->_tags->getResource();
63-
$this->_tags->getSelect()->joinLeft(
64-
['pt' => $resource->getTable('magefan_blog_post_tag')],
65-
'main_table.tag_id = pt.tag_id',
66-
[]
67-
)->joinLeft(
68-
['p' => $resource->getTable('magefan_blog_post')],
69-
'p.post_id = pt.post_id',
70-
[]
71-
)->joinLeft(
72-
['ps' => $resource->getTable('magefan_blog_post_store')],
73-
'p.post_id = ps.post_id',
74-
['count' => 'count(main_table.tag_id)']
75-
)->group(
76-
'main_table.tag_id'
77-
)->where(
78-
'ps.store_id IN (?)',
79-
[0, (int)$this->_storeManager->getStore()->getId()]
80-
);
65+
$this->_tags->getSelect()->joinLeft(
66+
['pt' => $resource->getTable('magefan_blog_post_tag')],
67+
'main_table.tag_id = pt.tag_id',
68+
[]
69+
)->joinLeft(
70+
['p' => $resource->getTable('magefan_blog_post')],
71+
'p.post_id = pt.post_id',
72+
[]
73+
)->joinLeft(
74+
['ps' => $resource->getTable('magefan_blog_post_store')],
75+
'p.post_id = ps.post_id',
76+
['count' => 'count(main_table.tag_id)']
77+
)->group(
78+
'main_table.tag_id'
79+
)->where(
80+
'ps.store_id IN (?)',
81+
[0, (int)$this->_storeManager->getStore()->getId()]
82+
);
83+
}
8184
}
8285

8386
return $this->_tags;

Block/Tag/AbstractTag.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © 2016-Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Block\Tag;
10+
11+
/**
12+
* Blog category abstract
13+
*/
14+
abstract class AbstractTag extends \Magento\Framework\View\Element\Template
15+
{
16+
/**
17+
* @var \Magento\Cms\Model\Template\FilterProvider
18+
*/
19+
protected $_filterProvider;
20+
21+
/**
22+
* @var \Magento\Framework\Registry
23+
*/
24+
protected $_coreRegistry;
25+
26+
/**
27+
* @var \Magefan\Blog\Model\Url
28+
*/
29+
protected $_url;
30+
31+
/**
32+
* Construct
33+
*
34+
* @param \Magento\Framework\View\Element\Context $context
35+
36+
* @param \Magento\Framework\Registry $coreRegistry,
37+
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
38+
* @param \Magefan\Blog\Model\Url $url
39+
* @param array $data
40+
*/
41+
public function __construct(
42+
\Magento\Framework\View\Element\Template\Context $context,
43+
\Magento\Framework\Registry $coreRegistry,
44+
\Magento\Cms\Model\Template\FilterProvider $filterProvider,
45+
\Magefan\Blog\Model\Url $url,
46+
array $data = []
47+
) {
48+
parent::__construct($context, $data);
49+
$this->_coreRegistry = $coreRegistry;
50+
$this->_filterProvider = $filterProvider;
51+
$this->_url = $url;
52+
}
53+
54+
/**
55+
* Retrieve category instance
56+
*
57+
* @return \Magefan\Blog\Model\Category
58+
*/
59+
public function getTag()
60+
{
61+
return $this->_coreRegistry->registry('current_blog_tag');
62+
}
63+
64+
/**
65+
* Retrieve post content
66+
*
67+
* @return string
68+
*/
69+
public function getContent()
70+
{
71+
$tag = $this->getTag();
72+
$key = 'filtered_content';
73+
if (!$tag->hasData($key)) {
74+
$cotent = $this->_filterProvider->getPageFilter()->filter(
75+
$tag->getContent()
76+
);
77+
$tag->setData($key, $cotent);
78+
}
79+
return $tag->getData($key);
80+
}
81+
}

Block/Tag/Info.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Block\Tag;
10+
11+
/**
12+
* Blog tag info
13+
*/
14+
class Info extends \Magefan\Blog\Block\Tag\AbstractTag
15+
{
16+
17+
}

Block/Tag/PostList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ protected function _prepareLayout()
4848
if ($tag = $this->getTag()) {
4949
$this->_addBreadcrumbs($tag->getTitle(), 'blog_tag');
5050
$this->pageConfig->addBodyClass('blog-tag-' . $tag->getIdentifier());
51-
$this->pageConfig->getTitle()->set($tag->getTitle());
51+
$this->pageConfig->getTitle()->set($tag->getMetaTitle());
52+
$this->pageConfig->setKeywords($tag->getMetaKeywords());
53+
$this->pageConfig->setDescription($tag->getMetaDescription());
5254
$this->pageConfig->addRemotePageAsset(
5355
$tag->getTagUrl(),
5456
'canonical',

Controller/Adminhtml/Tag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Tag extends Actions
2323
* Allowed Key
2424
* @var string
2525
*/
26-
protected $_allowedKey = 'Magefan_Blog::post';
26+
protected $_allowedKey = 'Magefan_Blog::tag';
2727

2828
/**
2929
* Model class name
@@ -35,5 +35,5 @@ class Tag extends Actions
3535
* Active menu key
3636
* @var string
3737
*/
38-
protected $_activeMenu = 'Magefan_Blog::post';
38+
protected $_activeMenu = 'Magefan_Blog::tag';
3939
}

Controller/Adminhtml/Tag/Delete.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag delete controller
13+
*/
14+
class Delete extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}

Controller/Adminhtml/Tag/Edit.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag edit controller
13+
*/
14+
class Edit extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}

Controller/Adminhtml/Tag/Grid.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag grid controller
13+
*/
14+
class Grid extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}

Controller/Adminhtml/Tag/Index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag list controller
13+
*/
14+
class Index extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag change status controller
13+
*/
14+
class MassStatus extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
namespace Magefan\Blog\Controller\Adminhtml\Tag;
10+
11+
/**
12+
* Blog tag create new controller
13+
*/
14+
class NewAction extends \Magefan\Blog\Controller\Adminhtml\Tag
15+
{
16+
17+
}

Controller/Tag/View.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public function execute()
3232

3333
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_blog_tag', $tag);
3434

35-
$this->_view->loadLayout();
36-
$this->_view->renderLayout();
35+
$resultPage = $this->_objectManager->get(\Magefan\Blog\Helper\Page::class)
36+
->prepareResultPage($this, $tag);
37+
38+
return $resultPage;
3739
}
3840

3941
/**
@@ -47,7 +49,7 @@ protected function _initTag()
4749

4850
$tag = $this->_objectManager->create(\Magefan\Blog\Model\Tag::class)->load($id);
4951

50-
if (!$tag->getId()) {
52+
if (!$tag->getId() || !$tag->isActive()) {
5153
return false;
5254
}
5355

Model/PreviewUrl.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function getUrl($object, $controllerName)
6262

6363
$url .= (false === strpos($url, '?')) ? '?' : '&';
6464
$url .= 'secret=' . $object->getSecret();
65-
6665
return $url;
6766
}
6867
}

Model/ResourceModel/Tag/Collection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ protected function _construct()
2525
parent::_construct();
2626
$this->_init('Magefan\Blog\Model\Tag', 'Magefan\Blog\Model\ResourceModel\Tag');
2727
}
28+
29+
/**
30+
* Retrieve true if post is active
31+
* @return boolean [description]
32+
*/
33+
public function addActiveFilter()
34+
{
35+
return $this
36+
->addFieldToFilter('is_active', 1);
37+
}
2838
}

0 commit comments

Comments
 (0)