|
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\Model\FrontModel; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
17
|
|
|
use CCDNForum\ForumBundle\Model\FrontModel\BaseModel; |
|
18
|
|
|
use CCDNForum\ForumBundle\Model\FrontModel\ModelInterface; |
|
19
|
|
|
use CCDNForum\ForumBundle\Entity\Post; |
|
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 PostModel extends BaseModel implements ModelInterface |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* |
|
36
|
|
|
* @access public |
|
37
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Post |
|
38
|
|
|
*/ |
|
39
|
|
|
public function createPost() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->getManager()->createPost(); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* |
|
46
|
|
|
* @access public |
|
47
|
|
|
* @param int $topicId |
|
48
|
|
|
* @param int $page |
|
49
|
|
|
* @param int $itemsPerPage |
|
50
|
|
|
* @param bool $canViewDeletedTopics |
|
51
|
|
|
* @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination |
|
52
|
|
|
*/ |
|
53
|
|
|
public function findAllPostsPaginatedByTopicId($topicId, $page, $itemsPerPage = 25, $canViewDeletedTopics = false) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getRepository()->findAllPostsPaginatedByTopicId($topicId, $page, $itemsPerPage, $canViewDeletedTopics); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* |
|
60
|
|
|
* @access public |
|
61
|
|
|
* @param int $postId |
|
62
|
|
|
* @param bool $canViewDeletedTopics |
|
63
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Post |
|
64
|
|
|
*/ |
|
65
|
|
|
public function findOnePostByIdWithTopicAndBoard($postId, $canViewDeletedTopics = false) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getRepository()->findOnePostByIdWithTopicAndBoard($postId, $canViewDeletedTopics); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* |
|
72
|
|
|
* @access public |
|
73
|
|
|
* @param int $topicId |
|
74
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Post |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getFirstPostForTopicById($topicId) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getRepository()->getFirstPostForTopicById($topicId); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
* @access public |
|
84
|
|
|
* @param int $topicId |
|
85
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Post |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getLastPostForTopicById($topicId) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getRepository()->getLastPostForTopicById($topicId); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* |
|
94
|
|
|
* @access public |
|
95
|
|
|
* @param int $topicId |
|
96
|
|
|
* @return Array |
|
97
|
|
|
*/ |
|
98
|
|
|
public function countPostsForTopicById($topicId) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getRepository()->countPostsForTopicById($topicId); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* |
|
105
|
|
|
* @access public |
|
106
|
|
|
* @param int $topicId |
|
|
|
|
|
|
107
|
|
|
* @return Array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function countPostsForUserById($userId) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->getRepository()->countPostsForUserById($userId); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* |
|
116
|
|
|
* @access public |
|
117
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
118
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface |
|
119
|
|
|
*/ |
|
120
|
|
|
public function savePost(Post $post) |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->getManager()->savePost($post); |
|
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* |
|
127
|
|
|
* @access public |
|
128
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
129
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface |
|
130
|
|
|
*/ |
|
131
|
|
|
public function updatePost(Post $post) |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getManager()->updatePost($post); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* |
|
138
|
|
|
* @access public |
|
139
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
140
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface |
|
141
|
|
|
*/ |
|
142
|
|
|
public function lock(Post $post) |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->getManager()->lock($post); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* |
|
149
|
|
|
* @access public |
|
150
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
151
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface |
|
152
|
|
|
*/ |
|
153
|
|
|
public function restore(Post $post) |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->getManager()->restore($post); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* |
|
160
|
|
|
* @access public |
|
161
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
162
|
|
|
* @param \Symfony\Component\Security\Core\User\UserInterface $user |
|
163
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface |
|
164
|
|
|
*/ |
|
165
|
|
|
public function softDelete(Post $post, UserInterface $user) |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->getManager()->softDelete($post, $user); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: