1
|
|
|
<?php |
2
|
|
|
namespace RbComment\View\Helper; |
3
|
|
|
|
4
|
|
|
use RbComment\Form\CommentForm; |
5
|
|
|
use RbComment\Model\CommentTable; |
6
|
|
|
use Zend\View\Helper\AbstractHelper; |
7
|
|
|
|
8
|
|
|
class Comment extends AbstractHelper |
9
|
|
|
{ |
10
|
|
|
protected $themes = [ |
11
|
|
|
'default' => true, |
12
|
|
|
'uikit' => true, |
13
|
|
|
'bootstrap3' => true, |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
private $viewHelperManager; |
17
|
|
|
private $routerService; |
18
|
|
|
private $configService; |
19
|
|
|
private $commentTable; |
20
|
|
|
|
21
|
|
|
public function __construct( |
22
|
|
|
$viewHelperManager, |
23
|
|
|
$routerService, |
24
|
|
|
array $configService, |
25
|
|
|
CommentTable $commentTable |
26
|
|
|
) { |
27
|
|
|
$this->viewHelperManager = $viewHelperManager; |
28
|
|
|
$this->routerService = $routerService; |
29
|
|
|
$this->configService = $configService; |
30
|
|
|
$this->commentTable = $commentTable; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function __invoke($theme = 'default') |
34
|
|
|
{ |
35
|
|
|
// If using a custom theme/partial do not append the prefix |
36
|
|
|
$invokablePartial = isset($this->themes[$theme]) |
37
|
|
|
? 'rbcomment/theme/' . $theme |
38
|
|
|
: $theme; |
39
|
|
|
|
40
|
|
|
$uri = $this->routerService->getRequestUri()->getPath(); |
41
|
|
|
$thread = sha1($uri); |
42
|
|
|
$validationMessages = $this->viewHelperManager->get('flashMessenger') |
43
|
|
|
->getMessagesFromNamespace('RbComment'); |
44
|
|
|
|
45
|
|
|
$strings = $this->configService['rb_comment']['strings']; |
46
|
|
|
|
47
|
|
|
echo $this->viewHelperManager->get('partial')->__invoke($invokablePartial, [ |
48
|
|
|
'comments' => $this->commentTable->fetchAllForThread($thread), |
49
|
|
|
'form' => new CommentForm($strings), |
50
|
|
|
'thread' => $thread, |
51
|
|
|
'validationResults' => count($validationMessages) > 0 |
52
|
|
|
? json_decode(array_shift($validationMessages)) |
53
|
|
|
: [], |
54
|
|
|
'uri' => $uri, |
55
|
|
|
'strings' => $strings, |
56
|
|
|
'zfc_user' => $this->configService['rb_comment']['zfc_user']['enabled'], |
57
|
|
|
'gravatar' => $this->configService['rb_comment']['gravatar']['enabled'], |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|