Skip to content

Commit cb1c37b

Browse files
committed
Build in comments. Not finished.
1 parent 1a0163f commit cb1c37b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2759
-90
lines changed

Block/Adminhtml/Comment.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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 post
13+
*/
14+
class Comment 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_Blog';
24+
$this->_blockGroup = 'Magefan_Blog';
25+
//$this->_addButtonLabel = __('Add New Comment');
26+
parent::_construct();
27+
$this->removeButton('add');
28+
}
29+
}

Block/Adminhtml/Grid/Column/Statuses.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public function getFrameCallback()
3535
public function decorateStatus($value, $row, $column, $isExport)
3636
{
3737
if ($row->getIsActive() || $row->getStatus()) {
38-
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
38+
if ($row->getStatus() == 2) {
39+
$cell = '<span class="grid-severity-minor"><span>' . $value . '</span></span>';
40+
} else {
41+
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
42+
}
3943
} else {
4044
$cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>';
4145
}

Block/Post/Info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Info extends \Magento\Framework\View\Element\Template
1919
* Block template file
2020
* @var string
2121
*/
22-
protected $_template = 'post/info.phtml';
22+
protected $_template = 'Magefan_Blog::post/info.phtml';
2323

2424
/**
2525
* DEPRECATED METHOD!!!!

Block/Post/PostList/AbstractList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function _preparePostCollection()
9494
*/
9595
public function getPostCollection()
9696
{
97-
if (is_null($this->_postCollection)) {
97+
if (null === $this->_postCollection) {
9898
$this->_preparePostCollection();
9999
}
100100

Block/Post/View/Comments.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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!
@@ -26,16 +26,16 @@ class Comments extends \Magento\Framework\View\Element\Template
2626
protected $_coreRegistry;
2727

2828
/**
29-
* Construct
30-
*
31-
* @param \Magento\Framework\View\Element\Context $context
32-
* @param \Magento\Framework\Registry $coreRegistry,
33-
* @param \Magento\Cms\Model\Page $post
34-
* @param \Magento\Framework\Registry $coreRegistry,
35-
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
36-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
37-
* @param \Magento\Cms\Model\PageFactory $postFactory
38-
* @param array $data
29+
* @var string
30+
*/
31+
protected $commetType;
32+
33+
/**
34+
* Constructor
35+
* @param \Magento\Framework\View\Element\Template\Context $context
36+
* @param \Magento\Framework\Registry $coreRegistry
37+
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
38+
* @param array $data
3939
*/
4040
public function __construct(
4141
\Magento\Framework\View\Element\Template\Context $context,
@@ -121,4 +121,18 @@ public function getPost()
121121
}
122122
return $this->getData('post');
123123
}
124+
125+
/**
126+
* Render block HTML
127+
*
128+
* @return string
129+
*/
130+
protected function _toHtml()
131+
{
132+
if ($this->commetType && $this->commetType != $this->getCommentsType()) {
133+
return '';
134+
}
135+
136+
return parent::_toHtml();
137+
}
124138
}

Block/Post/View/Comments/Disqus.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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\Post\View\Comments;
10+
11+
use Magefan\Blog\Model\Config\Source\CommetType;
12+
13+
/**
14+
* Blog post Disqus comments block
15+
*/
16+
class Disqus extends \Magefan\Blog\Block\Post\View\Comments
17+
{
18+
protected $commetType = CommetType::DISQUS;
19+
}

Block/Post/View/Comments/Facebook.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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\Post\View\Comments;
10+
11+
use Magefan\Blog\Model\Config\Source\CommetType;
12+
13+
/**
14+
* Blog post Facebook comments block
15+
*/
16+
class Facebook extends \Magefan\Blog\Block\Post\View\Comments
17+
{
18+
protected $commetType = CommetType::FACEBOOK;
19+
}

Block/Post/View/Comments/Google.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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\Post\View\Comments;
10+
11+
use Magefan\Blog\Model\Config\Source\CommetType;
12+
13+
/**
14+
* Blog post Google comments block
15+
*/
16+
class Google extends \Magefan\Blog\Block\Post\View\Comments
17+
{
18+
protected $commetType = CommetType::GOOGLE;
19+
}

Block/Post/View/Comments/Magefan.php

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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\Post\View\Comments;
10+
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magefan\Blog\Model\Config\Source\CommetType;
13+
14+
/**
15+
* Blog post Magefan comments block
16+
*/
17+
class Magefan extends \Magefan\Blog\Block\Post\View\Comments
18+
{
19+
protected $commetType = CommetType::MAGEFAN;
20+
21+
/**
22+
* @var \Magefan\Blog\Model\ResourceModel\Comment\Collection
23+
*/
24+
protected $commentCollection;
25+
26+
/**
27+
* @var string
28+
*/
29+
protected $defaultCommentBlock = 'Magefan\Blog\Block\Post\View\Comments\Magefan\Comment';
30+
31+
/**
32+
* @var \Magento\Customer\Model\Session
33+
*/
34+
protected $customerSession;
35+
36+
/**
37+
* @var \Magento\Customer\Model\Url
38+
*/
39+
protected $customerUrl;
40+
41+
/**
42+
* Constructor
43+
* @param \Magento\Framework\View\Element\Template\Context $context
44+
* @param \Magento\Framework\Registry $coreRegistry
45+
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
46+
* @param \Magento\Customer\Model\Session $customerSession
47+
* @param \Magento\Customer\Model\Url $customerUrl
48+
* @param array $data
49+
*/
50+
public function __construct(
51+
\Magento\Framework\View\Element\Template\Context $context,
52+
\Magento\Framework\Registry $coreRegistry,
53+
\Magento\Framework\Locale\ResolverInterface $localeResolver,
54+
\Magento\Customer\Model\Session $customerSession,
55+
\Magento\Customer\Model\Url $customerUrl,
56+
array $data = []
57+
) {
58+
parent::__construct($context, $coreRegistry, $localeResolver, $data);
59+
$this->customerSession = $customerSession;
60+
$this->customerUrl = $customerUrl;
61+
}
62+
63+
/**
64+
* Retrieve comment block
65+
*
66+
* @return \Magefan\Blog\Block\Post\View\Comments\Magefan\Comment
67+
*/
68+
public function getCommentBlock()
69+
{
70+
$k = 'comment_block';
71+
if (!$this->hasData($k)) {
72+
$blockName = $this->getCommentBlockName();
73+
if ($blockName) {
74+
$block = $this->getLayout()->getBlock($blockName);
75+
}
76+
77+
if (empty($block)) {
78+
$block = $this->getLayout()->createBlock($this->defaultCommentBlock, uniqid(microtime()));
79+
}
80+
81+
$this->setData($k, $block);
82+
}
83+
84+
return $this->getData($k);
85+
}
86+
87+
/**
88+
* Retrieve comment html
89+
*
90+
* @return string
91+
*/
92+
public function getCommentHtml(\Magefan\Blog\Model\Comment $comment)
93+
{
94+
return $this->getCommentBlock()
95+
->setComment($comment)
96+
->toHtml();
97+
}
98+
99+
/**
100+
* Prepare posts collection
101+
*
102+
* @return void
103+
*/
104+
protected function prepareCommentCollection()
105+
{
106+
$this->commentCollection = $this->getPost()->getComments()
107+
->addActiveFilter()
108+
->setPageSize(5)
109+
->setOrder('creation_time', 'DESC');
110+
111+
//if ($this->getPageSize()) {
112+
$this->commentCollection->setPageSize(5);
113+
//}
114+
}
115+
116+
/**
117+
* Prepare posts collection
118+
*
119+
* @return \Magefan\Blog\Model\ResourceModel\Post\Collection
120+
*/
121+
public function getCommentsCollection()
122+
{
123+
if (null === $this->commentCollection) {
124+
$this->prepareCommentCollection();
125+
}
126+
127+
return $this->commentCollection;
128+
}
129+
130+
/**
131+
* Retrieve customer session
132+
* @return \Magento\Customer\Model\Session
133+
*/
134+
public function getCustomerSession()
135+
{
136+
return $this->customerSession;
137+
}
138+
139+
/**
140+
* Retrieve customer url model
141+
* @return \Magento\Customer\Model\Url
142+
*/
143+
public function getCustomerUrl()
144+
{
145+
return $this->customerUrl;
146+
}
147+
148+
/**
149+
* Retrieve true if customer can post new comment or reply
150+
*
151+
* @return string
152+
*/
153+
public function canPost()
154+
{
155+
return $this->_scopeConfig->getValue(
156+
\Magefan\Blog\Helper\Config::GUEST_COMMENT,
157+
ScopeInterface::SCOPE_STORE
158+
) || $this->getCustomerSession()->getCustomerGroupId();
159+
}
160+
161+
/**
162+
* Retrieve form url
163+
* @return string
164+
*/
165+
public function getFormUrl()
166+
{
167+
return $this->getUrl('blog/comment/post');
168+
}
169+
170+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © 2015-2017 Ihor Vansach (ihor@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\Post\View\Comments\Magefan;
10+
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
/**
14+
* Magefan comment block
15+
*
16+
* @method string getComment()
17+
* @method $this setComment(\Magefan\Blog\Model\Comment $comment)
18+
*/
19+
class Comment extends \Magento\Framework\View\Element\Template
20+
{
21+
protected $_template = 'Magefan_Blog::post/view/comments/magefan/comment.phtml';
22+
23+
public function getReplies()
24+
{
25+
$comment = $this->getComment();
26+
if (!$comment->isReply()) {
27+
return $comment->getChildComments()
28+
->addActiveFilter()
29+
->setPageSize(5)
30+
->setOrder('creation_time', 'DESC');
31+
} else {
32+
return [];
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)