1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CCDNForum ForumBundle |
5
|
|
|
* |
6
|
|
|
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/> |
7
|
|
|
* |
8
|
|
|
* Available on github <http://www.github.com/codeconsortium/> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace CCDNForum\ForumBundle\Controller; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
17
|
|
|
|
18
|
|
|
use CCDNForum\ForumBundle\Component\Dispatcher\ForumEvents; |
19
|
|
|
use CCDNForum\ForumBundle\Component\Dispatcher\Event\UserPostResponseEvent; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @category CCDNForum |
24
|
|
|
* @package ForumBundle |
25
|
|
|
* |
26
|
|
|
* @author Reece Fowell <[email protected]> |
27
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
28
|
|
|
* @version Release: 2.0 |
29
|
|
|
* @link https://github.com/codeconsortium/CCDNForumForumBundle |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
class UserPostController extends UserPostBaseController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @access public |
37
|
|
|
* @param string $forumName |
38
|
|
|
* @param int $postId |
39
|
|
|
* @return RenderResponse |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function showAction($forumName, $postId) |
42
|
|
|
{ |
43
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
44
|
|
|
$this->isFound($post = $this->getPostModel()->findOnePostByIdWithTopicAndBoard($postId, true)); |
|
|
|
|
45
|
|
|
$this->isAuthorised($this->getAuthorizer()->canShowPost($post, $forum)); |
46
|
|
|
|
47
|
|
|
if ($this->isGranted('ROLE_USER')) { // get the topic subscriptions. |
48
|
|
|
$subscription = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($post->getTopic()->getId(), $this->getUser()->getId()); |
|
|
|
|
49
|
|
|
} else { |
50
|
|
|
$subscription = null; |
51
|
|
|
} |
52
|
|
|
$subscriberCount = $this->getSubscriptionModel()->countSubscriptionsForTopicById($post->getTopic()->getId()); |
53
|
|
|
|
54
|
|
|
return $this->renderResponse('CCDNForumForumBundle:User:Post/show.html.', array( |
55
|
|
|
'crumbs' => $this->getCrumbs()->addUserPostShow($forum, $post), |
56
|
|
|
'forum' => $forum, |
57
|
|
|
'forumName' => $forumName, |
58
|
|
|
'topic' => $post->getTopic(), 'post' => $post, |
59
|
|
|
'subscription' => $subscription, |
60
|
|
|
'subscription_count' => $subscriberCount, |
61
|
|
|
)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* @access public |
67
|
|
|
* @param string $forumName |
68
|
|
|
* @param int $postId |
69
|
|
|
* @return RedirectResponse|RenderResponse |
|
|
|
|
70
|
|
|
*/ |
71
|
|
|
public function editAction($forumName, $postId) |
72
|
|
|
{ |
73
|
|
|
$this->isAuthorised('ROLE_USER'); |
74
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
75
|
|
|
$this->isFound($post = $this->getPostModel()->findOnePostByIdWithTopicAndBoard($postId, true)); |
|
|
|
|
76
|
|
|
$this->isAuthorised($this->getAuthorizer()->canEditPost($post, $forum)); |
77
|
|
|
$formHandler = $this->getFormHandlerToEditPost($post); |
78
|
|
|
|
79
|
|
|
$response = $this->renderResponse('CCDNForumForumBundle:User:Post/edit.html.', array( |
80
|
|
|
'crumbs' => $this->getCrumbs()->addUserPostShow($forum, $post), |
81
|
|
|
'forum' => $forum, |
82
|
|
|
'forumName' => $forumName, |
83
|
|
|
'post' => $post, |
84
|
|
|
'preview' => $formHandler->getForm()->getData(), |
85
|
|
|
'form' => $formHandler->getForm()->createView(), |
86
|
|
|
)); |
87
|
|
|
$this->dispatch(ForumEvents::USER_POST_EDIT_RESPONSE, new UserPostResponseEvent($this->getRequest(), $response, $formHandler->getForm()->getData())); |
88
|
|
|
|
89
|
|
|
return $response; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* |
94
|
|
|
* @access public |
95
|
|
|
* @param string $forumName |
96
|
|
|
* @param int $postId |
97
|
|
|
* @return RedirectResponse|RenderResponse |
|
|
|
|
98
|
|
|
*/ |
99
|
|
|
public function editProcessAction($forumName, $postId) |
100
|
|
|
{ |
101
|
|
|
$this->isAuthorised('ROLE_USER'); |
102
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
103
|
|
|
$this->isFound($post = $this->getPostModel()->findOnePostByIdWithTopicAndBoard($postId, true)); |
|
|
|
|
104
|
|
|
$this->isAuthorised($this->getAuthorizer()->canEditPost($post, $forum)); |
105
|
|
|
$formHandler = $this->getFormHandlerToEditPost($post); |
106
|
|
|
|
107
|
|
|
if ($formHandler->process()) { |
108
|
|
|
$response = $this->redirectResponseForTopicOnPageFromPost($forumName, $formHandler->getForm()->getData()->getTopic(), $formHandler->getForm()->getData()); |
109
|
|
|
} else { |
110
|
|
|
$response = $this->renderResponse('CCDNForumForumBundle:User:Post/edit.html.', array( |
111
|
|
|
'crumbs' => $this->getCrumbs()->addUserPostShow($forum, $post), 'forum' => $forum, 'post' => $post, |
112
|
|
|
'forumName' => $forumName, |
113
|
|
|
'preview' => $formHandler->getForm()->getData(), 'form' => $formHandler->getForm()->createView(), |
114
|
|
|
)); |
115
|
|
|
} |
116
|
|
|
$this->dispatch(ForumEvents::USER_POST_EDIT_RESPONSE, new UserPostResponseEvent($this->getRequest(), $response, $formHandler->getForm()->getData())); |
117
|
|
|
|
118
|
|
|
return $response; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* |
123
|
|
|
* @access public |
124
|
|
|
* @param string $forumName |
125
|
|
|
* @param int $postId |
126
|
|
|
* @return RedirectResponse|RenderResponse |
|
|
|
|
127
|
|
|
*/ |
128
|
|
|
public function deleteAction($forumName, $postId) |
129
|
|
|
{ |
130
|
|
|
$this->isAuthorised('ROLE_USER'); |
131
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
132
|
|
|
$this->isFound($post = $this->getPostModel()->findOnePostByIdWithTopicAndBoard($postId, true)); |
|
|
|
|
133
|
|
|
$this->isAuthorised($this->getAuthorizer()->canDeletePost($post, $forum)); |
134
|
|
|
$formHandler = $this->getFormHandlerToDeletePost($post); |
135
|
|
|
$response = $this->renderResponse('CCDNForumForumBundle:User:Post/delete.html.', array( |
136
|
|
|
'crumbs' => $this->getCrumbs()->addUserPostDelete($forum, $post), |
137
|
|
|
'forum' => $forum, |
138
|
|
|
'forumName' => $forumName, |
139
|
|
|
'post' => $post, |
140
|
|
|
'form' => $formHandler->getForm()->createView(), |
141
|
|
|
)); |
142
|
|
|
$this->dispatch(ForumEvents::USER_POST_SOFT_DELETE_RESPONSE, new UserPostResponseEvent($this->getRequest(), $response, $formHandler->getForm()->getData())); |
143
|
|
|
|
144
|
|
|
return $response; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* |
149
|
|
|
* @access public |
150
|
|
|
* @param string $forumName |
151
|
|
|
* @param int $postId |
152
|
|
|
* @return RedirectResponse|RenderResponse |
|
|
|
|
153
|
|
|
*/ |
154
|
|
|
public function deleteProcessAction($forumName, $postId) |
155
|
|
|
{ |
156
|
|
|
$this->isAuthorised('ROLE_USER'); |
157
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
158
|
|
|
$this->isFound($post = $this->getPostModel()->findOnePostByIdWithTopicAndBoard($postId, true)); |
|
|
|
|
159
|
|
|
$this->isAuthorised($this->getAuthorizer()->canDeletePost($post, $forum)); |
160
|
|
|
$formHandler = $this->getFormHandlerToDeletePost($post); |
161
|
|
|
|
162
|
|
|
if ($formHandler->process()) { |
163
|
|
|
$response = $this->redirectResponseForTopicOnPageFromPost($forumName, $post->getTopic(), $post); |
|
|
|
|
164
|
|
|
} else { |
165
|
|
|
$response = $this->renderResponse('CCDNForumForumBundle:User:Post/delete.html.', array( |
166
|
|
|
'crumbs' => $this->getCrumbs()->addUserPostShow($forum, $post), |
167
|
|
|
'forum' => $forum, 'post' => $post, |
168
|
|
|
'forumName' => $forumName, |
169
|
|
|
'form' => $formHandler->getForm()->createView(), |
170
|
|
|
)); |
171
|
|
|
} |
172
|
|
|
$this->dispatch(ForumEvents::USER_POST_SOFT_DELETE_RESPONSE, new UserPostResponseEvent($this->getRequest(), $response, $formHandler->getForm()->getData())); |
173
|
|
|
|
174
|
|
|
return $response; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.