|
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\Component\Manager; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
17
|
|
|
|
|
18
|
|
|
use CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface; |
|
19
|
|
|
use CCDNForum\ForumBundle\Model\Component\Manager\ManagerInterface; |
|
20
|
|
|
use CCDNForum\ForumBundle\Model\Component\Manager\BaseManager; |
|
21
|
|
|
use CCDNForum\ForumBundle\Component\Helper\PostLockHelper; |
|
22
|
|
|
|
|
23
|
|
|
use CCDNForum\ForumBundle\Entity\Post; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* |
|
27
|
|
|
* @category CCDNForum |
|
28
|
|
|
* @package ForumBundle |
|
29
|
|
|
* |
|
30
|
|
|
* @author Reece Fowell <[email protected]> |
|
31
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
32
|
|
|
* @version Release: 2.0 |
|
33
|
|
|
* @link https://github.com/codeconsortium/CCDNForumForumBundle |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
class PostManager extends BaseManager implements ManagerInterface |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* |
|
40
|
|
|
* @access protected |
|
41
|
|
|
* @var \CCDNForum\ForumBundle\Component\Helper\PostLockHelper $postLockHelper |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $postLockHelper; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @access public |
|
48
|
|
|
* @param \CCDNForum\ForumBundle\Gateway\GatewayInterface $gateway |
|
|
|
|
|
|
49
|
|
|
* @param \CCDNForum\ForumBundle\Component\Helper\PostLockHelper $postLockHelper |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(GatewayInterface $gateway, PostLockHelper $postLockHelper) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->gateway = $gateway; |
|
54
|
|
|
$this->postLockHelper = $postLockHelper; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
* @access public |
|
60
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Post |
|
61
|
|
|
*/ |
|
62
|
|
|
public function createPost() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->gateway->createPost(); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* |
|
69
|
|
|
* @access public |
|
70
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
71
|
|
|
* @return \CCDNForum\ForumBundle\Manager\ManagerInterface |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
public function savePost(Post $post) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->postLockHelper->setLockLimitOnPost($post); |
|
76
|
|
|
|
|
77
|
|
|
$this->gateway->savePost($post); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
// refresh the user so that we have an PostId to work with. |
|
80
|
|
|
$this->refresh($post); |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
* @access public |
|
88
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
89
|
|
|
* @return \CCDNForum\ForumBundle\Manager\ManagerInterface |
|
|
|
|
|
|
90
|
|
|
*/ |
|
91
|
|
|
public function updatePost(Post $post) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->gateway->updatePost($post); |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* |
|
100
|
|
|
* @access public |
|
101
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
102
|
|
|
* @return \CCDNForum\ForumBundle\Manager\ManagerInterface |
|
|
|
|
|
|
103
|
|
|
*/ |
|
104
|
|
|
public function lock(Post $post) |
|
105
|
|
|
{ |
|
106
|
|
|
$post->setUnlockedUntilDate(new \Datetime('now')); |
|
107
|
|
|
$this->persist($post)->flush(); |
|
108
|
|
|
$this->refresh($post); |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* |
|
115
|
|
|
* @access public |
|
116
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
117
|
|
|
* @return \CCDNForum\ForumBundle\Manager\ManagerInterface |
|
|
|
|
|
|
118
|
|
|
*/ |
|
119
|
|
|
public function restore(Post $post) |
|
120
|
|
|
{ |
|
121
|
|
|
$post->setDeleted(false); |
|
122
|
|
|
$post->setDeletedBy(null); |
|
123
|
|
|
$post->setDeletedDate(null); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
// update the record |
|
126
|
|
|
$this->persist($post)->flush(); |
|
127
|
|
|
|
|
128
|
|
|
if ($post->getTopic()) { |
|
129
|
|
|
$topic = $post->getTopic(); |
|
130
|
|
|
|
|
131
|
|
|
// if this is the first post and only post, |
|
132
|
|
|
// then restore the topic aswell. |
|
133
|
|
|
if ($topic->getCachedReplyCount() < 1) { |
|
134
|
|
|
$topic->setDeleted(false); |
|
|
|
|
|
|
135
|
|
|
$topic->setDeletedBy(null); |
|
136
|
|
|
$topic->setDeletedDate(null); |
|
137
|
|
|
|
|
138
|
|
|
$this->persist($topic)->flush(); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* |
|
147
|
|
|
* @access public |
|
148
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Post $post |
|
149
|
|
|
* @param \Symfony\Component\Security\Core\User\UserInterface $user |
|
150
|
|
|
* @return \CCDNForum\ForumBundle\Manager\ManagerInterface |
|
|
|
|
|
|
151
|
|
|
*/ |
|
152
|
|
|
public function softDelete(Post $post, UserInterface $user) |
|
153
|
|
|
{ |
|
154
|
|
|
// Don't overwite previous users accountability. |
|
155
|
|
|
if (! $post->getDeletedBy() && ! $post->getDeletedDate()) { |
|
156
|
|
|
$post->setDeleted(true); |
|
157
|
|
|
$post->setDeletedBy($user); |
|
158
|
|
|
$post->setDeletedDate(new \DateTime()); |
|
159
|
|
|
|
|
160
|
|
|
// update the record |
|
161
|
|
|
$this->persist($post)->flush(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.