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\UserTopicEvent; |
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 UserSubscriptionController extends BaseController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @access public |
37
|
|
|
* @param string $forumName |
38
|
|
|
* @return RenderResponse |
|
|
|
|
39
|
|
|
*/ |
40
|
|
|
public function indexAction($forumName) |
41
|
|
|
{ |
42
|
|
|
$this->isAuthorised('ROLE_USER'); |
43
|
|
|
|
44
|
|
|
if ($forumName != '~') { |
45
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
46
|
|
|
} else { |
47
|
|
|
$forum = null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$page = $this->getQuery('page', 1); |
51
|
|
|
$filter = $this->getQuery('filter', 'all'); |
52
|
|
|
// Use this for the sidebar counters |
53
|
|
|
$subscriptionForums = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($this->getUser()->getId(), true); |
|
|
|
|
54
|
|
|
$forumsSubscribed = array(); |
55
|
|
|
$totalForumsSubscribed = array('count_read' => 0, 'count_unread' => 0, 'count_total' => 0); |
|
|
|
|
56
|
|
|
foreach ($subscriptionForums as $subscription) { |
57
|
|
|
$forumSubscribed = $subscription->getForum(); |
58
|
|
|
|
59
|
|
|
if ($forumSubscribed) { |
60
|
|
|
$forumSubscribedId = $forumSubscribed->getId(); |
61
|
|
|
|
62
|
|
|
if (! array_key_exists($forumSubscribedId, $forumsSubscribed)) { |
63
|
|
|
$forumsSubscribed[$forumSubscribedId] = array( |
64
|
|
|
'forum' => $forumSubscribed, |
65
|
|
|
'count_read' => 0, |
66
|
|
|
'count_unread' => 0, |
67
|
|
|
'count_total' => 0, |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$forumsSubscribed[$forumSubscribedId]['count_total']++; |
72
|
|
|
if ($subscription->isRead()) { |
73
|
|
|
$forumsSubscribed[$forumSubscribedId]['count_read']++; |
74
|
|
|
} else { |
75
|
|
|
$forumsSubscribed[$forumSubscribedId]['count_unread']++; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($forum) { |
79
|
|
|
if ($forum->getId() == $forumSubscribedId) { |
80
|
|
|
$totalForumsSubscribed['count_total']++; |
81
|
|
|
if ($subscription->isRead()) { |
82
|
|
|
$totalForumsSubscribed['count_read']++; |
83
|
|
|
} else { |
84
|
|
|
$totalForumsSubscribed['count_unread']++; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} else { |
88
|
|
|
$totalForumsSubscribed['count_total']++; |
89
|
|
|
if ($subscription->isRead()) { |
90
|
|
|
$totalForumsSubscribed['count_read']++; |
91
|
|
|
} else { |
92
|
|
|
$totalForumsSubscribed['count_unread']++; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Use this for the ALL/READ/UNREAD tab |
99
|
|
|
$itemsPerPage = $this->getPageHelper()->getTopicsPerPageOnSubscriptions(); |
100
|
|
|
if ($forumName == '~') { |
101
|
|
|
$subscriptionPager = $this->getSubscriptionModel()->findAllSubscriptionsPaginatedForUserById($this->getUser()->getId(), $page, $itemsPerPage, $filter, true); |
|
|
|
|
102
|
|
|
} else { |
103
|
|
|
$subscriptionPager = $this->getSubscriptionModel()->findAllSubscriptionsPaginatedForUserByIdAndForumById($forum->getId(), $this->getUser()->getId(), $page, $itemsPerPage, $filter, true); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->renderResponse('CCDNForumForumBundle:User:Subscription/show.html.', array( |
107
|
|
|
'forum' => $forum, |
108
|
|
|
'forumName' => $forumName, |
109
|
|
|
'subscribed_forums' => $forumsSubscribed, |
110
|
|
|
'total_subscribed_forums' => $totalForumsSubscribed, |
111
|
|
|
'filter' => $filter, |
112
|
|
|
'pager' => $subscriptionPager, |
113
|
|
|
'posts_per_page' => $this->container->getParameter('ccdn_forum_forum.topic.user.show.posts_per_page') |
114
|
|
|
)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* |
119
|
|
|
* @access public |
120
|
|
|
* @param string $forumName |
121
|
|
|
* @param int $topicId |
122
|
|
|
* @return RedirectResponse |
123
|
|
|
*/ |
124
|
|
|
public function subscribeAction($forumName, $topicId) |
125
|
|
|
{ |
126
|
|
|
$this->isAuthorised('ROLE_USER'); |
127
|
|
|
|
128
|
|
|
if ($forumName != '~') { |
129
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
130
|
|
|
} else { |
131
|
|
|
$forum = null; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->isFound($topic = $this->getTopicModel()->findOneTopicByIdWithBoardAndCategory($topicId)); |
|
|
|
|
135
|
|
|
$this->isAuthorised($this->getAuthorizer()->canSubscribeToTopic($topic, $forum)); |
136
|
|
|
$this->getSubscriptionModel()->subscribe($topic, $this->getUser())->flush(); |
137
|
|
|
$this->dispatch(ForumEvents::USER_TOPIC_SUBSCRIBE_COMPLETE, new UserTopicEvent($this->getRequest(), $topic, true)); |
138
|
|
|
|
139
|
|
|
return $this->redirectResponse($this->path('ccdn_forum_user_topic_show', array( |
140
|
|
|
'forumName' => $forumName, |
141
|
|
|
'topicId' => $topicId |
142
|
|
|
))); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* |
147
|
|
|
* @access public |
148
|
|
|
* @param string $forumName |
149
|
|
|
* @param int $topicId |
150
|
|
|
* @return RedirectResponse |
151
|
|
|
*/ |
152
|
|
|
public function unsubscribeAction($forumName, $topicId) |
153
|
|
|
{ |
154
|
|
|
$this->isAuthorised('ROLE_USER'); |
155
|
|
|
|
156
|
|
|
if ($forumName != '~') { |
157
|
|
|
$this->isFound($forum = $this->getForumModel()->findOneForumByName($forumName)); |
|
|
|
|
158
|
|
|
} else { |
159
|
|
|
$forum = null; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$this->isFound($topic = $this->getTopicModel()->findOneTopicByIdWithBoardAndCategory($topicId)); |
|
|
|
|
163
|
|
|
$subscription = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topicId, $this->getUser()->getId()); |
|
|
|
|
164
|
|
|
$this->isAuthorised($this->getAuthorizer()->canUnsubscribeFromTopic($topic, $forum, $subscription)); |
165
|
|
|
$this->getSubscriptionModel()->unsubscribe($topic, $this->getUser()->getId())->flush(); |
|
|
|
|
166
|
|
|
$this->dispatch(ForumEvents::USER_TOPIC_UNSUBSCRIBE_COMPLETE, new UserTopicEvent($this->getRequest(), $topic, false)); |
167
|
|
|
|
168
|
|
|
return $this->redirectResponse($this->path('ccdn_forum_user_topic_show', array( |
169
|
|
|
'forumName' => $forumName, |
170
|
|
|
'topicId' => $topicId |
171
|
|
|
))); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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.